I'd like to know the most elegant (and performant?) pattern to replace what I often code as:
names = []
for person in persons:
names.append(person.GetName())
I write this because it's how I'd write it in JavaScript, and I don't know any better. But I imagine there's something I can do with list comprehensions?
names = [person.GetName() for person in persons]
names = [person.GetName() for person in persons]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.