Advertisement
here2share

# b_if_any_3_in_sublists.py

Apr 15th, 2023 (edited)
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. # b_if_any_3_in_sublists.py
  2.  
  3. main_list = [[3, 4, 5, 6], [3, 1, 4, 2], [1, 0, 4, 2], [3, 2, 9, 0], [3, 1, 1, 1]] # Example main list
  4. nums = [9, 1, 2, 3] # Numbers to check
  5.  
  6. for sublist in main_list:
  7.     matching_count = 0
  8.     for num in nums:
  9.         if num in sublist:
  10.             matching_count += 1
  11.     if matching_count >= 3:
  12.         print("3 numbers from [9, 1, 2, 3] matches those in the sublist", sublist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement