Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Occurence
#2
First look at this, and take the time to understand it with the python documentation
>>> L = [1, 5, 2, 1, 2, 3, 5, 1, 5]
>>> sorted(set(L))
[1, 2, 3, 5]
Now replace lines 10 - 12 with
    for item in sorted(set(L)):
        count = L.count(item)
        print(item + ":" + "\""+str(count)+"\"" )
You can also remove L2 from the code.
Reply


Messages In This Thread
Occurence - by Adem - Nov-07-2019, 10:29 PM
RE: Occurence - by Gribouillis - Nov-07-2019, 10:48 PM
RE: Occurence - by perfringo - Nov-08-2019, 08:18 AM
RE: Occurence - by Adem - Nov-08-2019, 03:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up [SOLVED] Find last occurence of pattern in text file? Winfried 4 4,433 Aug-13-2021, 08:21 PM
Last Post: Winfried
  Delete minimum occurence in a string RavCOder 10 3,978 Nov-12-2019, 01:08 PM
Last Post: RavCOder

Forum Jump:

User Panel Messages

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