Python Forum
Removing existing tuples from a list of tuple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing existing tuples from a list of tuple
#2
'Bob' is not in the list
print('Bob' == ('Bob', '4562345'))
Output:
False
('Bob', '4562345') is in the list
data = [('Jill', '5239980'), ('Bob', '4562345'), ('Jenny', '2541273')]
print(data.index(('Bob', '4562345')))
Output:
1
To find the index of the tuple that 'Bob' is inside you would need to loop through the list comparing the first index item of each against 'Bob', you can use enumerate to get the index as you loop through.
Reply


Messages In This Thread
RE: Removing existing tuples from a list of tuple - by Yoriz - May-15-2021, 06:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework - List containing tuples containing dicti Men 4 2,095 Dec-28-2021, 12:37 AM
Last Post: Men
  Removing all strings in a list that are of x length Bruizeh 5 3,285 Aug-27-2021, 03:11 AM
Last Post: naughtyCat
  Input validation for nested dict and sorting list of tuples ranbarr 3 3,984 May-14-2021, 07:14 AM
Last Post: perfringo
  Removing items in a list cap510 3 2,386 Nov-01-2020, 09:53 PM
Last Post: cap510
  Removing items from list slackerman73 8 4,512 Dec-13-2019, 05:39 PM
Last Post: Clunk_Head
  Generating a list and a tuple Truman 3 7,798 Mar-15-2018, 09:20 PM
Last Post: wavic
  list of list to list of tuple? student8 2 3,004 Nov-14-2017, 08:06 AM
Last Post: buran
  need help removing an item from a list jhenry 4 4,260 Oct-13-2017, 08:15 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020