Iterate manually, using the condition to select a list to which each element will be appended:
good, bad = [], []
for x in mylist:
(bad, good)[x in goodvals].append(x)
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()`?
- How can I get list of values from dict?
- Converting a string representation of a list into an actual list object [duplicate]
- 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 input matrix (2D list) in Python?
- Check if list items contains substrings from another list
- 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?
- Comprehension on a nested iterables?
- Slicing a list into n nearly-equal-length partitions [duplicate]
- Overriding append method after inheriting from a Python List
- Why do these list methods (append, sort, extend, remove, clear, reverse) return None rather than the resulting list?
- Sorting list according to corresponding values from a parallel list [duplicate]
- Does Python have an immutable list?
- Mapping dictionary value to list
- How to change variables fed into a for loop in list form
- Length of longest word in a list
- list extend() to index, inserting list elements not only to the end