Python solution using a dict as switch case. Sadly I didn't had a cool idea about the "default" case wiithout using a default dict (didn't wanted to import anything)
defcreateString(persons):defFunc=lambdax:"{}, {} and {} others like this".format(x[0],x[1],len(x)-2)converter={0:lambdax:"{} likes this".format("no one"),1:lambdax:"{} likes this".format(x[0]),2:lambdax:"{} and {} like this".format(x[0],x[1]),3:lambdax:"{}, {} and {} like this".format(x[0],x[1],x[2])}returnconverter.get(len(persons),defFunc)(persons)assert(createString([])=="no one likes this")assert(createString(["Peter"])=="Peter likes this")assert(createString(["Jacob","Alex"])=="Jacob and Alex like this")assert(createString(["Max","John","Mark"])=="Max, John and Mark like this")assert(createString(["Alex","Jacob","Mark","Max"])=="Alex, Jacob and 2 others like this")
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python solution using a dict as switch case. Sadly I didn't had a cool idea about the "default" case wiithout using a default dict (didn't wanted to import anything)