attrs = [o.attr for o in objs]
was the right code for making a list like the one you describe. Don’t try to subclass list
for this. Is there something you did not like about that snippet?
More Related Contents:
- Accessing the index in ‘for’ loops
- Strange result when removing item from a list while iterating over it
- What is the most “pythonic” way to iterate over a list in chunks?
- Modifying list while iterating [duplicate]
- Iterate through pairs of items in a Python list [duplicate]
- Concatenating two lists – difference between ‘+=’ and extend()
- Removing Item From List – during iteration – what’s wrong with this idiom?
- Test if lists share any items in python
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- What’s the most Pythonic way to identify consecutive duplicates in a list?
- Python – TypeError: ‘int’ object is not iterable
- How to iterate over a list in chunks
- How to check if all of the following items are in a list?
- How do I loop through a list by twos? [duplicate]
- Assigning values to variables in a list using a loop
- python assign values to list elements in loop
- How to transform string of space-separated key,value pairs of unique words into a dict
- Why do I get “List index out of range” when trying to add consecutive numbers in a list using “for i in list”? [duplicate]
- Why does a for-loop with pop-method (or del statement) not iterate over all list elements [duplicate]
- Why doesn’t assigning to the loop variable modify the original list? How can I assign back to the list in a loop? [duplicate]
- How can I avoid “RuntimeError: dictionary changed size during iteration” error?
- Iterate over pairs in a list (circular fashion) in Python
- Loop over 2 lists, repeating the shortest until end of longest [duplicate]
- Python: find a list within members of another list(in order)
- Loop through list with both content and index [duplicate]
- Pythonic way to convert a list of integers into a string of comma-separated ranges
- Count duplicates between 2 lists
- How to find the maximum number in a list using a loop?
- Strange result when removing item from a list while iterating over it in Python
- Slicing a list into a list of sub-lists [duplicate]