Python Forum
Сheck if an element from a list is in another list that contains a namedtuple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Сheck if an element from a list is in another list that contains a namedtuple
#9
Don't remove, append. I would build a new list that only contains the requirements you want to keep, and I would use set operations to determine which requirements to save
from collections import namedtuple
from random import randint

Import = namedtuple("Import", ("module", "name", "alias"))

files = set(range(100, 200))

# All the requirements
requirements = [Import(randint(1, 1000), randint(1, 1000), randint(1, 1000)) for _ in range(10)]

# Requirements that have no match with any file.
requirements = [req for req in requirements if set(req).isdisjoint(files)]
print(*requirements, sep="\n")
elnk likes this post
Reply


Messages In This Thread
RE: Сheck if an element from a list is in another list that contains a namedtuple - by deanhystad - Oct-26-2022, 04:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 385 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  element in list detection problem jacksfrustration 5 527 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  list in dicitonary element problem jacksfrustration 3 793 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,307 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,654 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 968 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Find (each) element from a list in a file tester_V 3 1,286 Nov-15-2022, 08:40 PM
Last Post: tester_V
Question Keyword to build list from list of objects? pfdjhfuys 3 1,636 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,271 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  How to find the second lowest element in the list? Anonymous 3 2,089 May-31-2022, 01:58 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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