Ad
  • Default User Avatar

    good point of not using a dictonary!
    the other points should't be changed:
    don't leave out the slicing of 'names' inside format(), as this results in much slower performance for long name lists.
    making that if/else shorter degrades readability and performance
    same goes for separating the "like(s) this" part

    this would be a good approach:
    out = ( 0: 'no one likes this',
    1: '{} likes this',
    2: '{} and {} like this',
    3: '{}, {} and {} like this',
    4: '{}, {} and {others} others like this'
    )
    def likes(names):
    return out[min(4, len(names))].format(*names[:3], others=len(names)-2)

  • Default User Avatar

    thabks heeps!

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution