should look something like this:
if items in both lists (equal/ larger/smaller):
do something
else:
if items in both lists (equal/ larger/smaller):
do something
else:
do something
should look something like this:
if items in both lists (equal/ larger/smaller):
do something
else:
if items in both lists (equal/ larger/smaller):
do something
else:
do something
Well, it's unclear but seems like this is what you want:
list3 = [i for i in list2 if i not in list1]
Now:
print(list3)
Is:
[4]
If one element list, you care about, do:
print(next(iter(list3),list3))
Then output:
4
And if list3
is a list of more than 1 element for example:
[1,2]
This will still output:
[1,2]
Or ^
operator for sets (second part for slicing out first half of the list):
list3 = list(set(list2)^set(list1))
list3=list3[len(list3)//2:]
Now:
print(list3)
Is:
[4]
Then also can use next
stuff for list3
Or can do symmetric_difference
:
list3 = set.symmetric_difference(set(list1),set(list2))
list3=list(list3)[len(list3)//2:]
Now:
print(list3)
Is:
[4]
Can do same stuff for next
And as you want a while loop:
l=[i for i in list2 if i not in list1]
it=iter(l)
while l!=list3:
list3.append(next(it))
A dummy way of doing this tho ...
And now:
print(list3)
Is:
[4]
And can do same next
stuff
Or even better:
num = 0
while num < len(list2):
if list2[num] != list1[num]:
list3.append(list2[num])
num += 1
And now:
print(list3)
Is:
[4]
And can do same next
stuff