You probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.

Implement a function `likes :: [String] -> String`, which must take in input array, containing the names of people who like an item. It must return the display text as shown in the examples:

```python
likes([]) # must be "no one likes this"
likes(["Peter"]) # must be "Peter likes this"
likes(["Jacob", "Alex"]) # must be "Jacob and Alex like this"
likes(["Max", "John", "Mark"]) # must be "Max, John and Mark like this"
likes(["Alex", "Jacob", "Mark", "Max"]) # must be "Alex, Jacob and 2 others like this"
```

For 4 or more names, the number in `and 2 others` simply increases.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def likes(names):
	

Solutions:
def likes(names):
	n = len(names)
	return {0: 'no one likes this', 1: '{} likes this', 2: '{} and {} like this', 3: '{}, {} and {} like this', 4: '{}, {} and {others} others like this'}[min(4, n)].format(*names[:3], others=n - 2)


def likes(names):
	if len(names) == 0:
		return 'no one likes this'
	elif len(names) == 1:
		return '%s likes this' % names[0]
	elif len(names) == 2:
		return '%s and %s like this' % (names[0], names[1])
	elif len(names) == 3:
		return '%s, %s and %s like this' % (names[0], names[1], names[2])
	else:
		return '%s, %s and %s others like this' % (names[0], names[1], len(names) - 2)


def likes(names):
	if not names:
		return 'no one likes this'
	if len(names) == 1:
		first = ''
		second = names[0]
	elif len(names) == 2:
		first = names[0]
		second = names[1]
	elif len(names) == 3:
		first = ', '.join(names[:2])
		second = names[-1]
	else:
		first = ', '.join(names[:2])
		second = '%d others' % (len(names) - 2)
	if first:
		return first + ' and ' + second + ' like this'
	else:
		return second + ' likes this'


def likes(names):
	l = len(names)
	if l == 0:
		return 'no one likes this'
	if l == 1:
		return '{} likes this'.format(names[0])
	if l == 2:
		return '{} and {} like this'.format(names[0], names[1])
	if l == 3:
		return '{}, {} and {} like this'.format(names[0], names[1], names[2])
	return '{}, {} and {} others like this'.format(names[0], names[1], len(names) - 2)


def likes(names):
	if not names:
		return 'no one likes this'
	size = len(names)
	if size == 1:
		return '%s likes this' % names[0]
	if size == 2:
		return '%s and %s like this' % (names[0], names[1])
	if size == 3:
		return '%s, %s and %s like this' % (names[0], names[1], names[2])
	if size >= 4:
		return '%s, %s and %s others like this' % (names[0], names[1], len(names[2:]))


def likes(names):
	l = len(names)
	s = 'no one likes this'
	if l == 1:
		s = names[0] + ' likes this'
	elif l == 2:
		s = ' and '.join(names) + ' like this'
	elif l == 3:
		s = ', '.join(names[:-1]) + ' and ' + names[-1] + ' like this'
	elif l != 0:
		s = ', '.join(names[:2]) + ' and ' + str(l - 2) + ' others like this'
	return s