count occurrences of entry in list
I was having an issue with counting the occurrences of an item
in a list. eg
list= 'cat,cat,dog,rabbit,dog,cat' and i want result 'cat 3,dog 2, rabbit 1.
This is a very simplified example. What i actually wanted to do is:
I have a list of points, they are connected by a number of lines. i want the point to be larger based on the number of connections. each line from a point has 2 points of its own, so if there are 8 lines leading from a point there should be 9 points at that location.(1 for initial point and 1 for each line)
Any suggestions for a simpler way to achieve this would be
welcome, but i used a small python script.
# from collections import defaultdict
counts = defaultdict(int) for item in listx: counts[item] += 1 return dict(counts) # to use this you need to create a node with 'listx' as an input and also load "collections.py" from the same folder.
collections.py is part of python, you should easily find it online.
I have been away from python for a while and was never brilliant at it.
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac