Ad
Arrays
Sorting
Code
Diff
  • import re
    def longest_words(array, num):
        new = [k for k in sorted([''.join(re.findall(r"[A-Za-z]", j)) for j in array], key=lambda x: len(x), reverse=True) if k != ''] 
        return new[:num] if num <= len(new) else 'Invalid Parameters'
    • import re
    • def longest_words(array, num):
    • new = [k for k in sorted([''.join([i for i in j if 97 <= ord(i) <= 122 or 65 <= ord(i) <= 90]) for j in array], key=lambda x: len(x), reverse=True) if k != '']
    • new = [k for k in sorted([''.join(re.findall(r"[A-Za-z]", j)) for j in array], key=lambda x: len(x), reverse=True) if k != '']
    • return new[:num] if num <= len(new) else 'Invalid Parameters'