Python Forum
Use one list as search key for another list with sublist of list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use one list as search key for another list with sublist of list
#5
I got help on other site but I wanted to share the solution just in case anyone else has the same problem.

list1 = [['orange', [1, 2, 3]]]
list2 = [['apple', [1, 2, 3]], ['banana', [1, 2, 3]], ['pear', [-1, 2, 3]], ['kiwi', [1, -2, 3]]]

y = [x for x in list2 if x[1][0] not in [a[1][0] for a in list1]]
print(y)
Reply


Messages In This Thread
RE: Use one list as search key for another list with sublist of list - by jc4d - Jan-11-2022, 12:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Entry field random pull from list, each return own line Bear1981 6 718 Feb-25-2025, 06:09 AM
Last Post: Pedroski55
  removing one list element without using its index paul18fr 7 1,041 Feb-22-2025, 07:59 PM
Last Post: DeaD_EyE
  question about changing the string value of a list element jacksfrustration 4 2,006 Feb-08-2025, 07:43 AM
Last Post: jacksfrustration
  knowing for loop position in a list medic5678 4 659 Jan-31-2025, 04:19 PM
Last Post: perfringo
  help to parser arguments list absolut 3 605 Jan-15-2025, 03:19 AM
Last Post: BashBedlam
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 988 Nov-21-2024, 11:48 PM
Last Post: haihal
  List comprehension not working right Cris9855 3 917 Nov-04-2024, 03:46 PM
Last Post: DeaD_EyE
  What is a faster way to deep copy a nested list without using .deepcopy()? Shervin_Ataeian 1 1,343 Oct-13-2024, 01:28 PM
Last Post: Pedroski55
  Make a list learningpythonherenow 1 799 Oct-11-2024, 11:49 AM
Last Post: Pedroski55
  Merge list Simso 2 730 Oct-03-2024, 01:44 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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