The new NodeBox forum is live! Everything from support.nodebox.net moved here: sign in with the same email to pick up your old posts. Something not working? Write to forum-support@nodebox.net.

NodeBox 3From the old forum

count occurrences of entry in list

No replies yet

  1. 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
    def occurDict(listx):
    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.

    Copy link

Know something that helps?

Sign in with your email address to reply. No password needed.

Sign in to reply