how to print items within a nested dictionary where values are of list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to print items within a nested dictionary where values are of list

hi i tried to describe as best i could - so within a dictionary with lists as values how can i print side by side the correct indexes within each list while calling out each key- this is more of a how it works question i suppose https://code.sololearn.com/cdNfA32UeR9x/?ref=app

28th Nov 2021, 12:48 PM
ren[paused]
ren[paused] - avatar
11 Answers
+ 8
ren[paused] , to get the output as mentioned from you, we can use the zip() function to combine it like: 2021-06-10, 42.8 2021-06-11, 102.03 2021-06-12, 240.38 2021-06-13, 80.9 do a try with zip(), if you get stuck somewhere just post your attempt. happy coding!
28th Nov 2021, 1:30 PM
Lothar
Lothar - avatar
+ 2
Not sure what you mean, but look here https://code.sololearn.com/cyfM8V4Dz7Nx/?ref=app
28th Nov 2021, 1:07 PM
Slick
Slick - avatar
+ 1
Oh okay i gotcha. Pandas is good for this just because it's written in a way where everything is uniform. Using different data containers without the use of pandas just means you have to write specific code for whatever data set you're working with.
28th Nov 2021, 1:11 PM
Slick
Slick - avatar
+ 1
gah i forgot bout that one 🤯
28th Nov 2021, 1:30 PM
ren[paused]
ren[paused] - avatar
+ 1
i guess part of the idea is what do you do / best practice when you dont know entirely what oncoming data could be, but you need to build a container for it. that is what i think it feels like id be in for
28th Nov 2021, 1:31 PM
ren[paused]
ren[paused] - avatar
28th Nov 2021, 1:45 PM
ren[paused]
ren[paused] - avatar
+ 1
Nope! Lothar remembered a really useful one! As long as each list contains the same amount of values it doesnt matter how many keys you have. The zip method will stick each key[index] value into a tuple with the others of the same index. I forgot about that too haha
28th Nov 2021, 1:50 PM
Slick
Slick - avatar
0
yea like that! i am learning pandas and i wondered how else could it be done - i didnt know how to phrase my question better
28th Nov 2021, 1:09 PM
ren[paused]
ren[paused] - avatar
0
i kind of understand the basic idea for zip here? but when you dont know how many lists i guess you have to loop through them instead of statically input them like i just did :D
28th Nov 2021, 1:46 PM
ren[paused]
ren[paused] - avatar
0
from previous (sounds like this could be a job for unpack operator?)
28th Nov 2021, 1:50 PM
ren[paused]
ren[paused] - avatar
0
but do you need to resort to unpacking when it gets longer and you have 'a' : [0,1,2] , 'b : [1,3,10] , c : [0,8,9] and like many of these
29th Nov 2021, 1:41 AM
ren[paused]
ren[paused] - avatar