By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Grabbing the string 'hello' from a dictionary

P: 4
Expand|Select|Wrap|Line Numbers
  1.    d = {'k1':[{'nest_key':['this is deep',['hello']]}]}   
how would you grab the string 'hello' from this dictionary and why? Thanks!
Jun 19 '18 #1

✓ answered by Rabbit

The way I would approach it is to start reference the outer most layer and then dig inwards until you reach the value you're looking for.

This is obviously some sort of homework or exercise question, so giving you the answer out right won't help you learn anything.

Work through it. Get the first item and print it out. Then go another layer deeper and print that out. Keep adding layers till you get to the item you're looking for.

Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,365
The way I would approach it is to start reference the outer most layer and then dig inwards until you reach the value you're looking for.

This is obviously some sort of homework or exercise question, so giving you the answer out right won't help you learn anything.

Work through it. Get the first item and print it out. Then go another layer deeper and print that out. Keep adding layers till you get to the item you're looking for.
Jun 19 '18 #2

P: 4
It took me a while but I did figure it out, printing it out in pieces made it a lot easier, thanks for the advice!
Jun 20 '18 #3

Rabbit
Expert Mod 10K+
P: 12,365
No problem, good luck
Jun 20 '18 #4

Post your reply

Sign in to post your reply or Sign up for a free account.