3 ms·
persons = [person for person in (Person(name) for name in names) if person.isValid()] This is Python.
by carapace 10y ago
persons = [person for person in (Person(name) for name in names) if person.isValid()]
This is Python.
- contras1970 10y agoi've been struggling with python incomprehensions since time immemorial. map/filter are a breeze.
- laylomo 10y agoIt's easy. The first bit: [person tells you that you're getting a list of persons. That's the most important part. The rest is telling you how they're getting in that list. It's almost like a select query in (pseudo) SQL. select person from people where person.isvalid = true vs [person for person in people if person.isvalid]