Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
count item in list
#4
p.map is giving you a list, so there is no reason to append unless you want Final_List to be a list of lists. Your code fails because FinalList[0] is ['10.0.0.1:Success', '10.0.0.2:Success', '10.0.0.3:Error', '10.0.0.4:Offline' , '10.0.0.5:Error'], not '10.0.0.1:Success' as you are expecting. Change the code to something like this:
Final_List = p.map(GetUplaudFies, Device_List)
You can use a counter dictionary. But maybe it isn't right for this application since there are only 3 possible outcomes and they are all known. Your code should work with the above change. But this is a way to do it with a Counter
 outcomes = [outcome.split(':')[1] for outcome in Final_List]
outcomes = collections.Counter(outcomes)
for item, count in counter.items():
    print(item, count)
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,748 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Row Count and coloumn count Yegor123 4 1,374 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,668 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
Question Finding string in list item jesse68 8 1,928 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  How to get unique entries in a list and the count of occurrence james2009 5 3,024 May-08-2022, 04:34 AM
Last Post: ndc85430
  how to easily create a list of already existing item CompleteNewb 15 3,654 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,860 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Time.sleep: stop appending item to the list if time is early quest 0 1,894 Apr-13-2021, 11:44 AM
Last Post: quest
  list.count does not appear to function Oldman45 7 3,991 Mar-16-2021, 04:25 PM
Last Post: Oldman45
  How to run a pytest test for each item in a list arielma 0 2,385 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