1

I would like to use list comprehension. Have tried multiple iterations, just current one shown.

friends = ['Alice', 'Bob', 'Charlie', 'Derek']

cons_ends = [i for i in friends if i[-1] != ("a", "e", "i", "o", "u")]

print(cons_ends)

['Alice', 'Bob', 'Charlie', 'Derek']
Mark
  • 90,562
  • 7
  • 108
  • 148
typi
  • 35
  • 3
  • 3
    Use `if i[-1] not in ("a", "e", "i", "o", "u")` instead. (or better yet: `if i[-1] not in "aeiou"`) – Mark May 02 '21 at 19:02
  • 1
    See [Check if something is (not) in a list in Python](https://stackoverflow.com/q/10406130/15497888) and [Python Membership Operators Example](https://www.tutorialspoint.com/python/membership_operators_example.htm) – Henry Ecker May 02 '21 at 19:03

1 Answers1

0

This should work->

friends = ['Alice', 'Bob', 'Charlie', 'Derek']
friends = [x for x in friends if x[-1].lower() in ['a','e','i','o','u']]
print(friends)

Output ->

['Alice', 'Charlie']
KnowledgeGainer
  • 1,017
  • 1
  • 5
  • 14