How can I insert item into the array if its not already there?
This is what I tried:
[..]
k = []
for item in myarray:
if not item in k:
print("Item is in array already.")
k[] = item
Your code has the right idea but just use k.append(item)
instead of k[] = item
.
Also it is cleaner to say if item not in k:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With