U
U
Uno2016-05-24 00:51:35
Python
Uno, 2016-05-24 00:51:35

How to properly deal with lists?

Good afternoon Python3 and generator gurus.
l1 = [1,3,5]
l2 = [1,2,3,4,5]
l3 = [generator]
and l3 should contain [2,4], i.e. remove elements l1 from elements of l2...
Which one should be a generator?
Please help! I lost the source, where I made this thing for myself, now I need to do it again =(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-05-24
@Noizefan

generator?
if you need to subtract another from one set (set'a), then

In [8]: set(l2) - set(l1)
Out[8]: {2, 4}

if not set
In [9]: [x for x in l2 if x not in l1]
Out[9]: [2, 4]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question