In [5]: m=[[34,345,232],[23,343,342]]
In [7]: [[ subelt for subelt in elt if subelt != 345 ] for elt in m]
Out[7]: [[34, 232], [23, 343, 342]]
Note that remove(345)
only removes the first occurrance of of 345 (if it exists). The above code removes all occurrances of 345.
More Related Contents:
- how to unpack a tuple in this form (‘abc’, [20, 20])? [closed]
- Pandas column of lists, create a row for each list element
- What is the difference between `sorted(list)` vs `list.sort()`?
- What do ellipsis […] mean in a list?
- How can I get list of values from dict?
- Converting a string representation of a list into an actual list object [duplicate]
- Apply function to each element of a list
- Python list rotation [duplicate]
- List on python appending always the same value [duplicate]
- Why does ‘.sort()’ cause the list to be ‘None’ in Python? [duplicate]
- Python’s insert returning None?
- Convert NumPy array to Python list
- why sum on lists is (sometimes) faster than itertools.chain?
- appending list but error ‘NoneType’ object has no attribute ‘append’ [duplicate]
- Get number of items from list (or other iterable) with certain condition
- How to append multiple values to a list in Python
- How to remove square brackets from list in Python? [duplicate]
- accepting multiple user inputs separated by a space in python and append them to a list
- Unexpected list behavior in Python
- Why do these list operations (methods: clear / extend / reverse / append / sort / remove) return None, rather than the resulting list?
- Slicing a list into n nearly-equal-length partitions [duplicate]
- Can lists be mutated? [duplicate]
- How to return all list elements of a given length?
- Given parallel lists, how can I sort one while permuting (rearranging) the other in the same way?
- python remove duplicates from 2 lists
- Convert a number to a list of integers [duplicate]
- Unexpected Behavior of Extend with a list in Python [duplicate]
- Why Python `Memory Error` with list `append()` lots of RAM left
- How to change variables fed into a for loop in list form
- list extend() to index, inserting list elements not only to the end