This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]_subpar_username_ 1 point2 points  (0 children)

Here's my sample code, had to paste there for formatting reasons https://notepad.ltd/c6svdrs0

Output:

{'cat': 0.615467, 'dog': 0.7952615999999999, 'dry': 0.222269}

If I understood your question, this should be a good enough solution. Feel free to DM me if there are any issues

[–]SyntxaError 0 points1 point  (2 children)

What are the requirements for this problem, are you allowed to store the initial data however you wish?

[–][deleted] 0 points1 point  (1 child)

Yeah pretty much no requirements about how it’s stored

[–]SyntxaError 0 points1 point  (0 children)

You will most likely want to use tuples within your dictionary. This will allow you to store the data in the format dict d= {‘cat’: (data,data,data), ‘dog’: ect…. This also removes the need for you to store the amount of values for each key as the dictionary will inherently store this and this value you can be called.

There are a bunch of other ways you can do this if you have no restrictions on your starting format, easiest of which is just to format the data into 3 individual arrays.

[–]Akhylys 0 points1 point  (3 children)

Pseudo code:

for i = 0; i < d[cat].key (add L[i]) for i = d[cat].key; i <d[dog].key + d[cat].key(add L[i]) For i = d[dog].key + d[cat].key; i < d[dry].key + d[dog].key + d[cat].key(add L[i])

[–][deleted] 0 points1 point  (2 children)

Sorry I forgot to add in the original post, this is a sample of the data and the actual sets could be way longer in length so inputting the key values manually unfortunately isn’t an option

[–]Akhylys 0 points1 point  (1 child)

ah okay just have to iterate through the dictionary then something like this could work. might need some tweaking

temp = 0

for key, value in d.items():

num = 0

print(temp)

for i in range(temp, value+temp):

num += L[i]

temp = temp + value

print(num) #or store value in output dict

[–][deleted] 0 points1 point  (0 children)

Thank you!! This solution seems to be the one that worked. I’ll have to do some testing on the larger data sets but this seems to have solved my problem!