Grabbing the string 'hello' from a dictionary

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcdermottbobby
    New Member
    • Jun 2018
    • 4

    Grabbing the string 'hello' from a dictionary

    Code:
       d = {'k1':[{'nest_key':['this is deep',['hello']]}]}
    how would you grab the string 'hello' from this dictionary and why? Thanks!
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    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.

    Comment

    • mcdermottbobby
      New Member
      • Jun 2018
      • 4

      #3
      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!

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        No problem, good luck

        Comment

        Working...