Python Forum
count each element in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
count each element in a list
#1
hi guys , i want to print same element in each item in a list,
my code returns nothing except if i print list2,
it should return 3 elements in first item and 2 elements in a second one
    list1=[10,20,30,40]
    list2 =[[10,20,30,1],[10,20,1,2]]
    #print(list2)
    for i in list2:
        num= i.count(list1)
    if (num > 2):
        print(num)
Reply


Messages In This Thread
count each element in a list - by glennford49 - May-01-2020, 09:37 AM
RE: count each element in a list - by DPaul - May-01-2020, 09:45 AM
RE: count each element in a list - by pyzyx3qwerty - May-01-2020, 10:34 AM
RE: count each element in a list - by glennford49 - May-01-2020, 10:45 AM
RE: count each element in a list - by pyzyx3qwerty - May-01-2020, 10:47 AM
RE: count each element in a list - by glennford49 - May-01-2020, 10:50 AM
RE: count each element in a list - by anbu23 - May-01-2020, 11:09 AM
RE: count each element in a list - by glennford49 - May-01-2020, 11:20 AM
RE: count each element in a list - by glennford49 - May-01-2020, 10:37 AM
RE: count each element in a list - by anbu23 - May-01-2020, 10:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  element in list detection problem jacksfrustration 5 389 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  list in dicitonary element problem jacksfrustration 3 713 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  Function to count words in a list up to and including Sam Oldman45 15 6,612 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Find (each) element from a list in a file tester_V 3 1,236 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,852 Oct-26-2022, 04:03 PM
Last Post: deanhystad
  Row Count and coloumn count Yegor123 4 1,336 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,620 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,223 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  How to find the second lowest element in the list? Anonymous 3 2,024 May-31-2022, 01:58 PM
Last Post: Larz60+
  check if element is in a list in a dictionary value ambrozote 4 1,986 May-11-2022, 06:05 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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