For instance, here the item 2504994 and 2505056 are already in list 1. I want to remove from them from list 2.
I have the following error:
Traceback (most recent call last):
File “”, line 8, in
IndexError: index out of range: 9
Python not really my strongsuit, can anyone help please ?
I assume it’s because after you’ve remove a duplicate your range is no longer valid. Instead of trying to remove items I would suggest building a new list.
Iterate through each item in each sublist. Check to see if the item is already in a list of duplicates. If it’s already in your list of duplicates, skip it. If it’s not, append it to your new list and add it to the list of duplicates.
@Dmytro_Serebriian, I haven’t quite understood you code yet, but @AmolShah is right, I have the same problem when running the script.
Anyway, thank you so much to all of you for responding so quickly ! Your help is very constructive, I’m going to try out Nick’s method and I’ll keep you posted !
Yes, then its a quite different situation. In this case you need to add another level of looping.
It looks a bit fuzzy, so i think it is better try to use nodes.
In any way here is the python solution:
for j in range(len(list_final)-1):
for i in range(len(list_final)-ran):
Thanks you @Nick_Boyts and @Dmytro_Serebriian for your awesome help. Both of your scripts solve my problem. The upside of Nick’s method is that it keeps the order in the sublists, whereas Dmytro’s doesn’t. I’ll be sorting the lists afterwards anyway, so both work for me, but it’s good to keep that in mind. A big thank you