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,484
  • 10
  • 45
  • 70

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,512
  • 23
  • 27
Mazdak
  • 100,514
  • 17
  • 155
  • 179