0

How to remove common elements from two lists using while or for loop? Its showing list out of range

5th Aug 2021, 3:26 AM
Santhos raj
Santhos raj - avatar
9 Respuestas
0
Santhos raj Now I understood what you want. Do you want this: https://code.sololearn.com/cwzVH6FLZPw3/?ref=app
5th Aug 2021, 5:23 AM
A͢J
A͢J - avatar
+ 1
A͢J - S͟o͟l͟o͟ H͟e͟l͟p͟e͟r͟ they didn't teach set in my school. So I can't use set
5th Aug 2021, 4:43 AM
Santhos raj
Santhos raj - avatar
5th Aug 2021, 5:45 AM
Santhos raj
Santhos raj - avatar
0
Simple way add both list in a set. https://code.sololearn.com/cO4EstjRzLNP/?ref=app
5th Aug 2021, 4:13 AM
A͢J
A͢J - avatar
0
Santhos raj Ok but I have used for loop also. You can check shared code.
5th Aug 2021, 5:12 AM
A͢J
A͢J - avatar
0
Santhos raj do you want to remove common elements from both lists?
5th Aug 2021, 5:13 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
Eashan Morajkar You can try this for i in list2: if i not in list1: list1.append(i) print (list1)
5th Aug 2021, 5:14 AM
A͢J
A͢J - avatar
0
Santhos raj Here's a possibility: for x in list1: if x in list2: list1.remove(x) list2.remove(x) # Hope this helps
5th Aug 2021, 6:16 AM
Calvin Thomas
Calvin Thomas - avatar
0
Calvin Thomas thanks a lot
5th Aug 2021, 6:35 AM
Santhos raj
Santhos raj - avatar