[PYTHON] Various inclusion notations

List comprehension is a convenient notation for Python. Like this,

[a for a in [1, 2, 3, ]]

This way of writing can actually be used for other than lists.

dict

{ a: b for a, b in [(1, 2, ), (3, 4, ), ]}

set

set(a for a in [1, 2, 3, ])

Generator generation

(a for a in [1, 2, 3, ])

Check if there is data in the list that matches certain conditions

len([item for item in items if func(item)]) > 0
#func is a function for judging conditions

Recommended Posts

Various inclusion notations
Various scraping