Simplest solution may be to use an if
statement to first check if [5,6]
is not already in RESULT
, and if not, append
it, otherwise continue on, possibly report to the user that it was a duplicate and not appended:
myinput = [1,2,3]
RESULT = [[5,6], [4,5,8]]
RESULT.append(myinput)
l = [5,6]
if l not in RESULT:
RESULT.append(l)
else:
# Do something with RESULT
pass # or
# print('Duplicate not appended')
print(f'RESULT: {RESULT}')
raise(Exception(f'{l} is a duplicate and thus was not appended'))
output:
RESULT: [[5, 6], [4, 5, 8], [1, 2, 3]]
Traceback (most recent call last):
File "main.py", line 15, in <module>
raise(Exception(f'{l} is a duplicate and thus was not appended'))
Exception: [5, 6] is a duplicate and thus was not appended