3

I'm creating a list comprehension where I grab a list of keys from a dictionary, ignoring certain specified ones.

[x if x not in ignoreKeys else None for x in entity]

I'm currently using else None as my way of not appending the ignored keys, but ideally I would get the list comprehension to pass over that iteration. Unfortunately pass gives a syntax error, so I'm wondering if there might be some way I can emulate the pass functionality?

SuperBiasedMan
  • 9,814
  • 10
  • 45
  • 73

1 Answers1

5

You don't need else at all, just use if :

[x for x in entity if x not in ignoreKeys]

This will return the values that are not in ignoreKeys.

Stefan Gruenwald
  • 2,582
  • 24
  • 30
Mazdak
  • 105,000
  • 18
  • 159
  • 188