Dec-28-2020, 09:47 AM
(This post was last modified: Dec-28-2020, 09:47 AM by Pedroski55.)
# use set to get rid of duplicates like this numbers = [1, 2, 3, 1, 2, 3, 4, 1] unique_numbers = set(numbers) # this works great: splat it! numbers = [1, 2, 3, 1, 2, 3, 4, 1] unique_numbers2 = {*numbers} # you can't do this, because a list can't be a member of a set numbers = [1, 2, 3, 1, 2, 3, 4, 1] unique_numbers = {numbers} # to your problem mylist = [['seg', 'João', 3585], ['qui', 'João', 3847], ['seg', 'João', 3847], ['qua', 'João', 3913], ['qua', 'João', 3585]] # an empty set no_repeats = set() # add the contents of the sub-lists to no_repeats for item in mylist: aset = set(item) no_repeats.update(aset) # this returns: {3585, 3847, 3913, 'seg', 'qui', 'João', 'qua'} # if you need a list: result = list(no_repeats) # if you need a dictionary from this list, check out your last post