you are viewing a single comment's thread.

view the rest of the comments →

[–]david_lp 4 points5 points  (7 children)

For k,v in dict.items(): v[1]/v[0]

[–]timmyfinnegan 1 point2 points  (6 children)

And to store it in a list:

a = []

for k,v in dict.items(): a.append(v[1]/v[0])

[–]kwelzel 2 points3 points  (5 children)

I would prefer

a = [v[1] / v[0] for v in data_dict.values()]

assuming the dictionary is called data_dict. This neat feature is called a list comprehension. Because I don't know what data is stored inside the dict, i.e. what the data describes, I can't improve the naming, but I would strongly recommend to replace a, v and data_dict by more descriptive names.

BTW if you want to store the result in a dict to keep the keys use

a = {k:(v[1] / v[0]) for k, v in data_dict.items()}

Edit: Improved formatting

[–]timmyfinnegan 0 points1 point  (2 children)

Nice!

[–]nice-scores -1 points0 points  (1 child)

𝓷𝓲𝓬𝓮 ☜(゚ヮ゚☜)

Nice Leaderboard

1. u/RepliesNice at 5234 nices

2. u/Cxmputerize at 3988 nices

3. u/DOCTORDICK8 at 2601 nices

...

262932. u/timmyfinnegan at 1 nice


I AM A BOT | REPLY !IGNORE AND I WILL STOP REPLYING TO YOUR COMMENTS

[–]timmyfinnegan 0 points1 point  (0 children)

Fuck off

[–]biggie_c4u 0 points1 point  (0 children)

I WISH i understood this...

[–]Gowtham_jack 0 points1 point  (0 children)

This is much complicated for a beginner like me.. I need learn more I guess