Hello everyone this is actually my first question here so please tell me if I missing some information.
I have a list which contains numbers. I want to have all possible combinations and how often these combinations occur in my list. The combinations should follow the same rules as the itertools combinations library does it.
My first try was a loop, which saves the combinations in a dictionary, but I only accomplished that to a length of 2 numbers. After that my only idea was to loop again and again, but I guess this would take forever since my list will have more then 600 elements in it.
My first try looks like that:
def clean_dic(dic, sigma): #delete all canidates were frequency is smaller then sigma
dic = dict((k, v) for k, v in dic.items() if v >= sigma)
return dic
def create_canidate(seq,d_seq): #canidate creation with CDIST
for element in range(0,len(seq)):
s_check = set()
for skip in range (1,len(seq)-element):
number = tuple([seq[element], seq[element+skip]])
#get_freq
if number in d_seq and number not in s_check:
d_seq[number] += 1
elif number not in s_check and seq[element] in d_seq and seq[element+skip] in d_seq:
d_seq[number] = 1
s_check.add((seq[element], seq[element+skip]))
return d_seq
sequence = [1,2,3,4,1,2,1] #example sequence
#parameter
sigma = 2
#build dic
d_seq = dict()
d_seq = dict(Counter(sequence))
d_seq = clean_dic(d_seq, sigma)
d_seq = create_canidate(sequence, d_seq)
I already know that probably the best way to create all combinations would be to just use set(combinations(sequence, loop through all length)) but I cant figure out how I can then get the count without looping through everything anyway and not saving anything.....
So the question is: What would be the best way to achieve the task and how would that look like?
I would really appreciate your help :)
Regards,
Paul
Edit: Example for what I want to do. For the example Sequence [1,2,3,1,2] I would like to have the result: 1:2; 2:2; 3:1; 1,3:1; 1,1:1; 2,2:1; 2,3:1; 2,1:1; 3,1:1; 1,2,3:1; 1,2,1:1; 1,2,2:1; 1,3,1:1 ..... and so on. Note that the order has to be preserved.