in_tup = [('hello', 'hi', 'bye'), ('hello', 'yes', 'no'), ('alright', 'yes', 'okay')]
The goal is to remove the other tuples. The code will allow the user to accept the first 2 indexes which it will remove the whole tuple. This is my code so far:
first = input()
second = input()
out_tup = [i for i in in_tup if i[0] == first]
out_tup1 = [i for i in out_tup if i[1] == second]
for i in out_tup1:
a = ("{}, {}, {} has been removed".format(i[0],i[1],i[2]))
print(a)
a = [i for i in in_tup if in_tup != out_tup1]
print(a)
But when I input, for example "hello" and "hi" it still prints everything:
[('hello', 'hi', 'bye'), ('hello', 'yes', 'no'), ('alright', 'yes', 'okay')]
I want the output to only have these:
[('hello', 'yes', 'no'), ('alright', 'yes', 'okay')]
Seems to me that the condition in_tup != out_tup1
is True since you're comparing two lists of different length when the inputs are "hello" and "hi".
I believe that what you are trying to do is check whether the elements of in_tup are in out_tup1, so try the following:
a = [i for i in in_tup if i not in out_tup1]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments