fork download
  1. def all_the_longest(l):
  2. lst = [l[0]]
  3. for word in l:
  4. if len(word) > len(lst[-1]):
  5. while len(lst) > 0 and len(word) > len(lst[-1]):
  6. lst.pop()
  7. lst.append(word)
  8. if len(word) == len(lst[-1]) and word != lst[-1]:
  9. lst.append(word)
  10. return lst
  11. if __name__ == '__main__':
  12. print(all_the_longest(["Seraenina", "Gandalf", "Harry", "Walter"]))
Success #stdin #stdout 0.1s 14080KB
stdin
Standard input is empty
stdout
['Seraenina']