I have an array of objects
[<obj1>, <obj2>, <obj3>, <obj4>]
I want to get something like
[obj1.name, obj2.name, obj3.name, obj4.name]
I do not want to use loop for this, just looking for some more efficient way to get this
I have an array of objects
[<obj1>, <obj2>, <obj3>, <obj4>]
I want to get something like
[obj1.name, obj2.name, obj3.name, obj4.name]
I do not want to use loop for this, just looking for some more efficient way to get this
Turning @Tomerikoo's comment into an answer:
Use a list comprehension:
[o.name for o in l]
Note that this will not necessarily be more efficient than looping, but obviously more beautiful.
I think this will help you:
l = [<obj1>, <obj2>, <obj3>, <obj4>]
list(map(lambda x:x.name, l))