No; a list comprehension produces a list that is just as long as its input. You will need one of Python’s other functional tools (specifically reduce()
in this case) to fold the sequence into a single value.
More Related Contents:
- How to convert list containing string of elemet to list in python [closed]
- How do I sort a list of dictionaries by a value of the dictionary?
- How do I get the number of elements in a list in Python?
- How do you remove duplicates from a list whilst preserving order?
- Get the cartesian product of a series of lists?
- Does “IndexError: list index out of range” when trying to access the N’th item mean that my list has less than N items?
- From list of integers, get number closest to a given value
- sort() and reverse() functions do not work
- How to split elements of a list?
- Loop “Forgets” to Remove Some Items [duplicate]
- List vs tuple, when to use each? [duplicate]
- Deleting multiple elements from a list
- Function changes list values and not variable values in Python [duplicate]
- Extending list returns None [duplicate]
- Interleaving Lists in Python [duplicate]
- Confused about __str__ on list in Python [duplicate]
- join two lists of dictionaries on a single key
- Confusing […] List in Python: What is it?
- How to delete an item in a list if it exists?
- Flattening a list recursively [duplicate]
- remove None value from a list without removing the 0 value
- Python: Remove Duplicate Items from Nested list
- Changing one dict changes all dicts in a list of dicts [duplicate]
- Python string.join(list) on object array rather than string array
- How to sort multidimensional array by column?
- sum each value in a list of tuples
- Convert a number to a list of integers [duplicate]
- Unexpected Behavior of Extend with a list in Python [duplicate]
- Find non-common elements in lists
- Skip elements on a condition based in a list comprehension in python