How to remove tuples nested on a list?

casio_3000
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')]
milsek

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to unpack tuples in nested list?

From Dev

How to unpack tuples in nested list?

From Dev

How to round every float in a nested list of tuples

From Dev

How to makes tuples from a nested list

From Dev

How to convert a two nested list of lists into a nested list of tuples in Python?

From Dev

How to flatten a list of tuples and remove the duplicates?

From Dev

Python - How to remove duplicate tuples in a list of lists?

From Dev

Python Nested tuples to list

From Dev

How to convert nested list of lists into a list of tuples in python 3.3?

From Dev

Python convert list of nested tuples to list of tuples

From Dev

How to remove duplicates from a list of tuples but keeping the original order

From Dev

How to remove all strings from a list of tuples python

From Dev

How can i remove the even number indexes in a list of tuples?

From Dev

How to find (and remove) a nested object from a List

From Dev

How to find (and remove) a nested object from a List

From Dev

how to remove an element from a nested list lisp

From Dev

How to remove duplicate rows from nested list?

From Dev

Nested List of Lists to Single List of tuples

From Dev

How to input a list of tuples

From Dev

How to sum a list of tuples

From Dev

How to create a list of tuples

From Dev

How to create a list of tuples

From Dev

How to convert a list to a list of tuples?

From Dev

Changing nested list of numbers to nested list o tuples

From Dev

Creating a nested dictionary from a list of tuples

From Dev

Python convert a list of nested tuples into a dict

From Dev

Unpacking nested tuples using list comprehension

From Dev

Split long list of tuples into nested lists

From Dev

sum the count of duplicate in a nested list of tuples

Related Related

  1. 1

    How to unpack tuples in nested list?

  2. 2

    How to unpack tuples in nested list?

  3. 3

    How to round every float in a nested list of tuples

  4. 4

    How to makes tuples from a nested list

  5. 5

    How to convert a two nested list of lists into a nested list of tuples in Python?

  6. 6

    How to flatten a list of tuples and remove the duplicates?

  7. 7

    Python - How to remove duplicate tuples in a list of lists?

  8. 8

    Python Nested tuples to list

  9. 9

    How to convert nested list of lists into a list of tuples in python 3.3?

  10. 10

    Python convert list of nested tuples to list of tuples

  11. 11

    How to remove duplicates from a list of tuples but keeping the original order

  12. 12

    How to remove all strings from a list of tuples python

  13. 13

    How can i remove the even number indexes in a list of tuples?

  14. 14

    How to find (and remove) a nested object from a List

  15. 15

    How to find (and remove) a nested object from a List

  16. 16

    how to remove an element from a nested list lisp

  17. 17

    How to remove duplicate rows from nested list?

  18. 18

    Nested List of Lists to Single List of tuples

  19. 19

    How to input a list of tuples

  20. 20

    How to sum a list of tuples

  21. 21

    How to create a list of tuples

  22. 22

    How to create a list of tuples

  23. 23

    How to convert a list to a list of tuples?

  24. 24

    Changing nested list of numbers to nested list o tuples

  25. 25

    Creating a nested dictionary from a list of tuples

  26. 26

    Python convert a list of nested tuples into a dict

  27. 27

    Unpacking nested tuples using list comprehension

  28. 28

    Split long list of tuples into nested lists

  29. 29

    sum the count of duplicate in a nested list of tuples

HotTag

Archive