Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
count item in list
#9
items = ['A', 'B', 'A', 'B', 'C', 'A', 'A']
key = sorted(set(items))
for k in key:
    print(k, items.count(k))
Output:
A 4 B 2 C 1
Reply


Messages In This Thread
count item in list - by korenron - Jun-30-2021, 01:23 PM
RE: count item in list - by deanhystad - Jun-30-2021, 01:31 PM
RE: count item in list - by korenron - Jun-30-2021, 01:53 PM
RE: count item in list - by deanhystad - Jun-30-2021, 02:04 PM
RE: count item in list - by korenron - Jun-30-2021, 03:22 PM
RE: count item in list - by DeaD_EyE - Jun-30-2021, 03:38 PM
RE: count item in list - by korenron - Jul-01-2021, 08:48 AM
RE: count item in list - by deanhystad - Jul-01-2021, 01:46 PM
RE: count item in list - by naughtyCat - Aug-18-2021, 06:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to count words in a list up to and including Sam Oldman45 15 6,613 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  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
Question Finding string in list item jesse68 8 1,887 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  How to get unique entries in a list and the count of occurrence james2009 5 2,995 May-08-2022, 04:34 AM
Last Post: ndc85430
  how to easily create a list of already existing item CompleteNewb 15 3,573 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,767 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Time.sleep: stop appending item to the list if time is early quest 0 1,884 Apr-13-2021, 11:44 AM
Last Post: quest
  list.count does not appear to function Oldman45 7 3,945 Mar-16-2021, 04:25 PM
Last Post: Oldman45
  How to run a pytest test for each item in a list arielma 0 2,376 Jan-06-2021, 10:40 PM
Last Post: arielma

Forum Jump:

User Panel Messages

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