DEV Community

loading...

Discussion on: Daily Challenge #48 - Facebook Likes

Collapse
idanarye profile image
Idan Arye

Also Python, but using a different approach:

def likes(users):
    for fmt in [
        'no one likes this',
        '%s likes this',
        '%s and %s like this',
        '%s, %s and %s like this',
    ]:
        try:
            return fmt % tuple(users)
        except TypeError:
            pass
    u1, u2, *rest = users
    return '%s, %s and %s others like this' % (u1, u2, len(rest))