there are huge number of data, there are various groups. i want to check whether the new data fits in any group and if it does i want to put that data into that group. If datum doesn't fit to any of the group, i want to create 开发者_运维技巧new group. So, i want to use linked list for the purpose or is there any other way to doing so??
P.S. i have way to check the similarity between data and group representative(lets not go that in deatil for now) but i dont know how to add the data to group (each group may be list) or create new one if required. i guess what i needis linked list implementation in python, isn't it?
This sounds like a perfect use for a dictionary.
I would suggest using a dictionary (or defaultdict), where the key is the group and the value is a list of all data. Here is a simple example:
>>> from collections import defaultdict
>>> get_group = lambda x: x % 4
>>> d = defaultdict(list)
>>> for value in range(10):
... d[get_group(value)].append(value)
...
>>> dict(d)
{0: [0, 4, 8], 1: [1, 5, 9], 2: [2, 6], 3: [3, 7]}
精彩评论