Coding

Python – Accessing Nested Dictionary Keys

  • 00:00:01 welcome to another Pyfrom video in this
  • 00:00:04 video we'll have a look at how we can
  • 00:00:06 access information in nested
  • 00:00:09 dictionaries for that we need nested
  • 00:00:12 data and this is the data we will use
  • 00:00:14 for the purpose as you can see this is
  • 00:00:16 data in JSON format so we'll also learn
  • 00:00:19 how we can access well information
  • 00:00:21 stored in the JSON format in Python and
  • 00:00:24 the data is extracted from the Q&A
  • 00:00:26 section of our angular 7 course on udemy
  • 00:00:29 because students can ask questions and
  • 00:00:31 normally they will get answers for that
  • 00:00:33 we have some results right here because
  • 00:00:36 we retrieve this data from an API and we
  • 00:00:39 can see that we have a question right
  • 00:00:42 here this one from the angular course as
  • 00:00:45 I said and we also got replies inside
  • 00:00:48 the replies we can see that the reply is
  • 00:00:50 the class answer and we got a user and
  • 00:00:52 this user has a name the display name
  • 00:00:54 right here in that case it's max now the
  • 00:00:57 same thing right here we have another
  • 00:00:58 question we have replies we have the
  • 00:01:01 first reply again from Max and we got
  • 00:01:04 another reply from Danielle right here
  • 00:01:06 by the way not the real name of the
  • 00:01:08 student now and this goes on a bit right
  • 00:01:10 here down there with some other students
  • 00:01:12 and in the end what I want to achieve
  • 00:01:14 right here in Python is I want to create
  • 00:01:17 a list and save this list in JSON format
  • 00:01:19 which includes all these names right
  • 00:01:23 here so I want to have a list of all the
  • 00:01:25 people who answer questions in our Q&A
  • 00:01:28 thread right here in the angular course
  • 00:01:30 as I said just an excerpt though so
  • 00:01:32 that's what we want to do in this video
  • 00:01:33 so let's get started
  • 00:01:37 to get started you need two things you
  • 00:01:40 need – and you need a trip return
  • 00:01:42 notebook running we talked about that in
  • 00:01:44 another video and the second thing you
  • 00:01:47 need is you need a folder in here not a
  • 00:01:49 test folder that was just for well
  • 00:01:51 testing purposes but you need the source
  • 00:01:53 folder and inside the source folder you
  • 00:01:55 should put this source data
  • 00:01:57 J'son file you can find a link to that
  • 00:01:58 file below in the video description then
  • 00:02:01 navigate back to the main folder so the
  • 00:02:04 folder where you save the state at Hume
  • 00:02:05 and create a new – free notebook right
  • 00:02:09 here you can give it any name you want
  • 00:02:10 let's call it may be nested dict like
  • 00:02:15 that now what I first want to do is I
  • 00:02:17 want to access the information stored in
  • 00:02:20 that file for that and only me to do one
  • 00:02:23 thing I must import the JSON encoder for
  • 00:02:27 Python and this is pretty simple because
  • 00:02:29 you only have to type import Jason like
  • 00:02:32 that
  • 00:02:33 if you now hit shift and enter well you
  • 00:02:35 can get started because now we can use
  • 00:02:37 the functionality of this Chasen encoder
  • 00:02:40 – well open this chase and file for that
  • 00:02:43 we simply type with open like that and
  • 00:02:48 now we open brackets and add single
  • 00:02:50 quotation marks because now we have to
  • 00:02:52 specify either the file name of the file
  • 00:02:55 that you want to open this is true in
  • 00:02:57 case the file is stored in the same
  • 00:02:59 folder wherever you are currently
  • 00:03:00 working in in our case we store the file
  • 00:03:03 in the source folder so what we have to
  • 00:03:05 do right now is we have to add dot slash
  • 00:03:07 because we want to start well navigating
  • 00:03:10 starting from our current position and
  • 00:03:13 then we add the name of the folder which
  • 00:03:15 is source and now the name of the file
  • 00:03:18 which is source data dot jason like that
  • 00:03:23 so now we want to open this file stored
  • 00:03:26 in that folder and we have to give this
  • 00:03:28 a name which could be access Jason for
  • 00:03:33 example and then we have to add a colon
  • 00:03:35 right here because now we said that we
  • 00:03:37 want to open that file but we didn't
  • 00:03:40 tell Python what you want to do with
  • 00:03:41 that information in this file for that
  • 00:03:44 we simply enter maybe read content you
  • 00:03:47 can give it any name of your choice
  • 00:03:49 right here and read content should be
  • 00:03:51 you what well it should be equal to
  • 00:03:54 something that turns this JSON data into
  • 00:03:58 a so-called Python object because Python
  • 00:04:02 by default
  • 00:04:02 cannot work with Jason beta with fraud
  • 00:04:05 Jason data you could say it needs to
  • 00:04:08 have a structure which it understands a
  • 00:04:10 so-called – object in the end and for
  • 00:04:13 the purpose so to turn this jason data
  • 00:04:15 into a so-called – object we can now use
  • 00:04:18 our jason encoder once again that we
  • 00:04:20 imported right here because by typing
  • 00:04:23 jason dot load right here we simply tell
  • 00:04:27 – to turn this file and the content of
  • 00:04:30 this file so of our source data jason
  • 00:04:33 into a Python object we'll have a closer
  • 00:04:35 look at that in a few seconds and by
  • 00:04:37 that make it readable for Python and
  • 00:04:39 this also allows us to access the
  • 00:04:41 content in the end now with Jason load
  • 00:04:43 we simply have to add in brackets the
  • 00:04:46 name that we defined right here
  • 00:04:48 so access jason access jason like that
  • 00:04:53 if we now it shift and enter you can see
  • 00:04:56 well nothing basically but entering the
  • 00:04:58 name of our variable right here and
  • 00:05:00 hitting shift and enter basically shows
  • 00:05:03 us the content of our adjacent file now
  • 00:05:06 as we turned it into a Python object now
  • 00:05:09 what type of a Python object do we
  • 00:05:12 actually have right here well if you add
  • 00:05:14 type in front of your variable like this
  • 00:05:18 and like that
  • 00:05:19 and hit shift and enter you can see that
  • 00:05:21 we are working with a so called
  • 00:05:23 dictionary here I will not dive into the
  • 00:05:26 details about dictionaries in this video
  • 00:05:28 make sure to have a look at the link
  • 00:05:30 that you can find in the video
  • 00:05:31 description though but generally we can
  • 00:05:35 access information stored in
  • 00:05:38 dictionaries by accessing the so-called
  • 00:05:40 key in the dictionary now this sounds a
  • 00:05:43 little bit strange now let's maybe
  • 00:05:45 delete the type right here and the
  • 00:05:47 bracket and display the results so what
  • 00:05:49 i'm referring to basically is that this
  • 00:05:51 curly brace is right here indicate that
  • 00:05:54 we have a dictionary in Python and that
  • 00:05:57 this dictionary basically contains this
  • 00:05:59 single key right here we have more
  • 00:06:02 information in here that follows after
  • 00:06:03 that right here
  • 00:06:05 and right there up to here but all this
  • 00:06:09 information is the so-called value of
  • 00:06:11 this dictionary
  • 00:06:12 so to summarize that we have the results
  • 00:06:15 key right here now dictionary and the
  • 00:06:17 value which contains this list more
  • 00:06:20 about lists or how we can access tight
  • 00:06:21 end lists in a few seconds now in Python
  • 00:06:24 if it would refer to this key right here
  • 00:06:27 we would also be able to display the
  • 00:06:29 corresponding value of that key and
  • 00:06:31 that's exactly what we want because
  • 00:06:33 remember in the end my goal is to create
  • 00:06:36 a list of all the display name values
  • 00:06:39 right here so of the key display name
  • 00:06:41 which contains the value of the person
  • 00:06:44 who gave an answer to a question right
  • 00:06:46 here so for that we simply use our
  • 00:06:49 variable right here once again so read
  • 00:06:52 content read content and now enter
  • 00:06:55 square brackets and now we only have to
  • 00:06:58 add single quotation marks and refer to
  • 00:07:00 the key which contains the values that
  • 00:07:03 you want to display in our case this is
  • 00:07:05 the results key right here so if we
  • 00:07:07 enter results now like this and hit
  • 00:07:10 shift and enter we can see that we now
  • 00:07:12 display the entire value that our
  • 00:07:17 results key contains now let's maybe
  • 00:07:20 also give this material name
  • 00:07:22 maybe question access because that's to
  • 00:07:27 basically have right here and hit shift
  • 00:07:29 and enter once again and if we now enter
  • 00:07:31 type question access once again like
  • 00:07:36 this you can see that the type of our
  • 00:07:39 data changed because as I said
  • 00:07:41 previously we had a dictionary now we
  • 00:07:44 access the values of this dictionary and
  • 00:07:47 the values that this dictionary contains
  • 00:07:49 are not dictionaries or something like
  • 00:07:53 that or single values it is a single
  • 00:07:54 value but a special signal value it's a
  • 00:07:57 list right here so let's maybe get rid
  • 00:07:59 of our type once again and have a look
  • 00:08:02 at the result so this list right here in
  • 00:08:04 – also as for the dictionary more about
  • 00:08:07 lists can be found in the video
  • 00:08:09 description the list right here we have
  • 00:08:11 is well indicated by this square
  • 00:08:14 brackets right here and ending right
  • 00:08:16 there and this is basically now
  • 00:08:19 the enteric content that we have in our
  • 00:08:21 list the problem with this list is that
  • 00:08:23 we cannot access list items the way we
  • 00:08:26 did it before for the dictionary so if I
  • 00:08:28 would write something like question
  • 00:08:31 access like this open curly the square
  • 00:08:38 brackets and maybe access I don't know
  • 00:08:40 the course right here which could be in
  • 00:08:42 here so let's say course then this is
  • 00:08:45 not working because as our error mesh
  • 00:08:48 message shows right here list indices
  • 00:08:51 must be integers or slices not strings
  • 00:08:54 I don't know dive into slices now but we
  • 00:08:56 could use an integer for example so we
  • 00:08:58 could enter something like 1 right here
  • 00:09:00 and then we would access the list item
  • 00:09:04 with the index 1 and surprisingly the
  • 00:09:08 list item with the index 1 if you maybe
  • 00:09:10 keep that name right here in mind so the
  • 00:09:14 list item with the index 1 it's not this
  • 00:09:16 one right here right but it's the second
  • 00:09:21 one that one right here
  • 00:09:22 Daniel weed why because accessing list
  • 00:09:25 items starts with a number of 0 for the
  • 00:09:28 first item so appear and then if you
  • 00:09:33 want to access the second one you will
  • 00:09:34 enter an index of 1 and so on so if I
  • 00:09:39 would change this right here to 0 like
  • 00:09:41 that then we would access indeed our
  • 00:09:44 first list item which we have up here so
  • 00:09:47 max but there so these are basically our
  • 00:09:49 list items as you can see right here our
  • 00:09:51 list items again our dictionaries and
  • 00:09:54 now you can also see why this video is
  • 00:09:56 about accessing nested dictionaries
  • 00:09:59 because we basically have a dictionary
  • 00:10:01 which contains a list which contains a
  • 00:10:03 dictionary which again then contains a
  • 00:10:05 list and so on so that's this nesting
  • 00:10:07 structure we talk about in this video
  • 00:10:09 now the thing is that with this logic
  • 00:10:11 right here we can access a single list
  • 00:10:14 item but actually we want to access all
  • 00:10:16 our list items right here now if we want
  • 00:10:20 to kind of repeat something to get all
  • 00:10:22 the results a for loop might be
  • 00:10:24 something useful here for that we can
  • 00:10:27 get rid of that and we simply enter 4
  • 00:10:31 because this indicates that we want to
  • 00:10:33 such a loop right here now we can give
  • 00:10:35 this a name so here we could call this
  • 00:10:37 maybe question data something like that
  • 00:10:41 you can name this as you prefer the
  • 00:10:43 important thing is that you then add in
  • 00:10:45 and in what well in our question access
  • 00:10:48 because we basically want to retrieve
  • 00:10:51 the information we have in our list
  • 00:10:54 right here
  • 00:10:54 so for that we enter in question access
  • 00:11:00 like this and now we simply print our
  • 00:11:05 question data that we defined right here
  • 00:11:08 so let's see what the result will look
  • 00:11:11 like and as you can see the result looks
  • 00:11:14 quite good because now we were able to
  • 00:11:17 access the information in our list have
  • 00:11:21 a look at the square bracket at the
  • 00:11:22 square bracket which are gone now and
  • 00:11:24 now we can basically display the actual
  • 00:11:27 content but surprisingly as you can see
  • 00:11:30 if I enter type question data so up here
  • 00:11:35 the type of that information we have in
  • 00:11:38 our loop if I enter that oops not like
  • 00:11:40 that if I enter type question data you
  • 00:11:44 can see we have a dictionary once again
  • 00:11:46 but that's actually one of the core
  • 00:11:49 things already that I want to talk about
  • 00:11:50 in this video we learned how we can
  • 00:11:52 access dictionaries and how we can
  • 00:11:54 access lists and as we have both kind of
  • 00:11:57 nested into each other we cannot use the
  • 00:11:59 information we learned previously and
  • 00:12:01 access our information in our dictionary
  • 00:12:04 remember we can now access a specific
  • 00:12:06 key in our dictionary to retrieve the
  • 00:12:08 value now which keys do we have in our
  • 00:12:11 dictionary well we basically have the
  • 00:12:14 class key the question not the question
  • 00:12:17 the course key then we have another
  • 00:12:19 dictionary right here and then we have
  • 00:12:21 the replies key now why don't we access
  • 00:12:24 the replies key and see what values this
  • 00:12:27 key contains little spoiler it should be
  • 00:12:30 this list right here but we'll see
  • 00:12:32 so let's now enter maybe replies access
  • 00:12:37 to all the gift is a name because now we
  • 00:12:40 finally access our replies and we can
  • 00:12:42 access this replies by enter question
  • 00:12:45 data which we previously defined
  • 00:12:47 now again the square brackets and now
  • 00:12:50 enter replies adhere because this is
  • 00:12:53 what we want to access let's shift and
  • 00:12:56 enter and type replies access once again
  • 00:12:59 and as you can see we now printed our
  • 00:13:03 replies right here
  • 00:13:04 well actually we didn't because we
  • 00:13:07 printed our replies so we can access the
  • 00:13:10 replies key or the value the replies key
  • 00:13:12 contains but we printed this one right
  • 00:13:15 here so the last reply because what –
  • 00:13:18 basically that's before our logic is it
  • 00:13:19 basically has a look at all the
  • 00:13:21 information it has and returns the last
  • 00:13:23 matching information so the last
  • 00:13:25 matching here that we have right here
  • 00:13:27 will have a look at how you can resolve
  • 00:13:30 this in a few seconds but for the moment
  • 00:13:33 we are able to access our replies which
  • 00:13:35 is quite cool the problem is that if I
  • 00:13:38 enter type once again like this and like
  • 00:13:43 that we have a list once again but with
  • 00:13:47 our new knowledge we cannot simply add
  • 00:13:49 another for loop to access the
  • 00:13:51 information in our replies for that we
  • 00:13:54 type 4 and now maybe I don't know how
  • 00:13:57 our previous naming was question data so
  • 00:14:00 that's maybe call it replies data then
  • 00:14:02 as I said you're totally free here so
  • 00:14:04 for replies data in replies access
  • 00:14:07 you're not free here you have to use the
  • 00:14:09 name right here that you gave to this
  • 00:14:11 variable support applies data in replies
  • 00:14:15 access please print our replies data so
  • 00:14:19 let's see what's inside there basically
  • 00:14:21 and as you can see well no big surprise
  • 00:14:24 our replies
  • 00:14:26 access contains another dictionary so
  • 00:14:31 basically this dictionary right here
  • 00:14:32 well actually we have three dictionaries
  • 00:14:35 to be more precise here now we almost
  • 00:14:37 finished our primary goal we are almost
  • 00:14:41 able to access the display name right
  • 00:14:42 here but for that we again have to
  • 00:14:45 access a specific here for dictionary to
  • 00:14:47 retrieve the corresponding value now for
  • 00:14:50 that let's maybe call this user name now
  • 00:14:55 because we can now simply say that we
  • 00:14:59 want to access
  • 00:15:00 reply's data appear so our result of the
  • 00:15:04 for-loop open the square brackets and
  • 00:15:08 now access user well actually if think
  • 00:15:11 back about what we just learned we will
  • 00:15:13 access the last user here so this one so
  • 00:15:16 we can enter user oops
  • 00:15:18 like that but as we have a dictionary
  • 00:15:23 well nested inside of another dictionary
  • 00:15:26 we cannot simply add the square brackets
  • 00:15:31 once again and now simply refer to the
  • 00:15:33 key that we want to access in this
  • 00:15:35 nested dictionary
  • 00:15:37 specifically in our case this is the
  • 00:15:39 display name key right here so if I
  • 00:15:42 enter display name now like that and hit
  • 00:15:46 shift and enter and type username once
  • 00:15:49 again like this then you can see that we
  • 00:15:53 finally made it we are not able to
  • 00:15:55 access for all these nested dictionaries
  • 00:15:58 and lists our display name of next right
  • 00:16:01 here so this last name so that is the
  • 00:16:03 basic process how you can access these
  • 00:16:06 nested information at this nested data
  • 00:16:08 we have two problems though at the
  • 00:16:11 moment we only return one result so the
  • 00:16:14 display name right here the last one and
  • 00:16:16 actually my goal was to access to
  • 00:16:18 information retrieve all the display
  • 00:16:21 names so all the names of people who
  • 00:16:23 answered questions in our course and
  • 00:16:26 then basically save this list to a new
  • 00:16:29 JSON file let's take care of that fact
  • 00:16:32 that we only get back one result at the
  • 00:16:34 moment because we actually have all the
  • 00:16:37 need right here which has need to you
  • 00:16:39 well put it into another structure a
  • 00:16:41 different structure which in our case
  • 00:16:43 could be a function in Python now let's
  • 00:16:46 write this function and see how this
  • 00:16:48 works
  • 00:16:48 writing a function simply works with def
  • 00:16:51 right here now we have to define a
  • 00:16:54 function name maybe get user names
  • 00:16:57 something like that then we add the
  • 00:17:00 brackets which won't contain anything in
  • 00:17:02 our case right here and now we add the
  • 00:17:04 colon and now this function will not be
  • 00:17:07 built from scratch because we actually
  • 00:17:09 have all the information we need which
  • 00:17:11 has have to combine it in a function to
  • 00:17:13 make sure this
  • 00:17:14 function runs our loops again and again
  • 00:17:17 up until it found all the relevant
  • 00:17:20 information that we need so what this
  • 00:17:22 means for us is up until it found all
  • 00:17:24 the this plain name keys and returned
  • 00:17:28 all the corresponding values now to get
  • 00:17:32 started we have to scroll up a little
  • 00:17:33 bit up to here right there this is the
  • 00:17:37 first thing we need because what we
  • 00:17:39 basically want to do is we want to first
  • 00:17:41 open our file and read the content and
  • 00:17:44 after that we want to run our function
  • 00:17:46 that's the logic that's why I don't
  • 00:17:48 include this part right here in our
  • 00:17:50 function but as soon as we open our file
  • 00:17:53 we want to run our function and then
  • 00:17:55 this function should give us back the
  • 00:17:57 values of the results key right here in
  • 00:17:59 our dictionary so let's paste this right
  • 00:18:01 here so with the access to the values of
  • 00:18:05 the results key we can scroll up once
  • 00:18:07 again I'm not up to here up to here now
  • 00:18:09 because now we can take the for loop
  • 00:18:13 without the print statement because we
  • 00:18:15 don't need to print our data now we only
  • 00:18:17 need to for loop so we basically go down
  • 00:18:20 right here and paste this right there
  • 00:18:22 because what you're saying here is that
  • 00:18:23 please access the value and once you
  • 00:18:26 access the value with question access
  • 00:18:28 right here please give me back all the
  • 00:18:30 list items we have inside this list
  • 00:18:33 because remember question access is of
  • 00:18:36 type list we can see this right here you
  • 00:18:41 can see it it's a list so we got our for
  • 00:18:43 loop and this for loop returns question
  • 00:18:45 data and question data again is a
  • 00:18:47 dictionary so we can now simply copy
  • 00:18:50 this part right here after all for loop
  • 00:18:54 because the for loop was running so it
  • 00:18:56 basically says well please give me back
  • 00:18:58 all the information in our list and then
  • 00:19:00 please give me access to the values that
  • 00:19:03 we have for our replies key right here
  • 00:19:06 in our question data that's what we have
  • 00:19:09 right here so we are almost there and
  • 00:19:10 now we simply use our last for loop this
  • 00:19:14 one right here and paste it right there
  • 00:19:17 because now we simply want to say okay
  • 00:19:19 please give me back all the list items
  • 00:19:21 that we have in our replies access right
  • 00:19:25 here so basically all the list items
  • 00:19:28 in here and then finally just give me
  • 00:19:33 back the username with this code right
  • 00:19:37 there
  • 00:19:37 so as you can see we basically just
  • 00:19:40 summarize the information that we
  • 00:19:42 created previously before the code put
  • 00:19:44 it into function and also made sure that
  • 00:19:47 with this for loops now integrated in
  • 00:19:49 this function that we will not only
  • 00:19:51 retrieve back one single result so not
  • 00:19:54 only one single name right here but
  • 00:19:56 actually with that logic right here
  • 00:19:58 being part of that function and running
  • 00:20:00 all these for loops for all the results
  • 00:20:01 it can find it should actually give us
  • 00:20:03 back the names of all the persons who
  • 00:20:05 answered any question in our course
  • 00:20:08 right here now to see if this works we
  • 00:20:11 can also add a final print statement
  • 00:20:13 right here and simply print the user
  • 00:20:15 name right here let's see if this works
  • 00:20:18 now we do this and now we only have to
  • 00:20:21 call the function I get user names
  • 00:20:24 don't forget the brackets and if we do
  • 00:20:27 that we can see that we indeed get back
  • 00:20:30 a list of all the people who gave an
  • 00:20:33 answer in the corresponding course so
  • 00:20:36 that's cool but actually I wanted to
  • 00:20:38 save this information now to a new JSON
  • 00:20:41 file for that we have to tweak our code
  • 00:20:44 one less time a little bit the first
  • 00:20:46 thing I want to do right here is I want
  • 00:20:48 to create an empty list let's maybe call
  • 00:20:51 this list save data something like that
  • 00:20:54 and make it empty as you can see right
  • 00:20:56 here now what I want to do is once I run
  • 00:20:59 this function I want to make sure that
  • 00:21:02 the information or the result of that
  • 00:21:04 function is added to our empty list
  • 00:21:07 because the list is empty if I run the
  • 00:21:09 function well if it adds that
  • 00:21:11 information well the list contains
  • 00:21:13 exactly the data that you want to have
  • 00:21:15 in here for that we simply delete that
  • 00:21:19 print statement right here and refer to
  • 00:21:21 our list right there our variable that
  • 00:21:24 we defined right here so this should be
  • 00:21:25 oops not like that so this should be
  • 00:21:28 like that safe data and now dot and now
  • 00:21:35 we can at tab if you want you and now
  • 00:21:36 you can see what we need already we need
  • 00:21:38 to use a pen right here because append
  • 00:21:41 will simply add
  • 00:21:42 that information to this list right here
  • 00:21:44 so if we use the append method and add a
  • 00:21:48 bracket and now refer to the result
  • 00:21:50 right here so our username so user name
  • 00:21:55 like that and hit shift and enter we
  • 00:21:57 should now be able to add the
  • 00:21:59 information to our lists so if we run
  • 00:22:01 this code right here and now run our get
  • 00:22:05 usernames function like that and if you
  • 00:22:08 now access your list right here so by
  • 00:22:10 just typing safe data you can see that
  • 00:22:15 we indeed created a list right here
  • 00:22:17 which contains all our names that we
  • 00:22:20 have now the problem still is that we
  • 00:22:22 don't save that to a file but this can
  • 00:22:25 now be added easily by simply well
  • 00:22:27 deleting that and now we again use our
  • 00:22:29 with open code we learned that at the
  • 00:22:32 beginning of this video and now we give
  • 00:22:35 this file a name because we want you
  • 00:22:37 well create a new file right here so
  • 00:22:39 user names new something like that we
  • 00:22:44 want to write code to this file so we
  • 00:22:46 add the W right here and now we give it
  • 00:22:48 a name maybe as file I don't know give
  • 00:22:51 it a name of your choice at the colon
  • 00:22:53 and now simply add not jason load you
  • 00:22:56 remember the beginning we use chase and
  • 00:22:58 load to turn the jason code into a
  • 00:23:00 Python object now we want to turn the
  • 00:23:02 Python object back to a file which
  • 00:23:04 contains chase and data so we simply add
  • 00:23:07 Jason dot dump right here so load
  • 00:23:09 becomes dump now what information should
  • 00:23:14 be part of that file well it should of
  • 00:23:16 course be our safe data right here so we
  • 00:23:20 enter save data and now we add file this
  • 00:23:24 one right here once again to the end of
  • 00:23:26 our code if we do that and did it
  • 00:23:30 correctly and hit shift and enter we
  • 00:23:34 should be able to navigate back to our
  • 00:23:36 folder where we saved all that
  • 00:23:38 information then you should see that we
  • 00:23:40 made a mistake right here or I did
  • 00:23:42 because it's not a JSON file let me see
  • 00:23:44 oh yeah I'm sorry I forgot to add dot
  • 00:23:48 jason right here sorry my bad make sure
  • 00:23:50 to add dot jason and run the code once
  • 00:23:53 again but if you now go back
  • 00:23:56 you should see another file which now
  • 00:23:57 contains JSON data so if you right-click
  • 00:24:00 on to that and open it in my case I will
  • 00:24:02 do it with Visual Studio code for
  • 00:24:03 example you can see that if you format
  • 00:24:06 the data quickly that we indeed have a
  • 00:24:09 list of all the people who wrote an
  • 00:24:11 answer to the question in the phred
  • 00:24:13 saved as JSON data so that was it
  • 00:24:18 these were some core concepts of Python
  • 00:24:21 kind of wrapped into a well as I think
  • 00:24:23 practical example that you might also
  • 00:24:26 use from time to time it probably won't
  • 00:24:28 be the last
  • 00:24:29 Python data related tutorial right here
  • 00:24:32 but I hope as always that this was
  • 00:24:34 helpful for you and it would be great to
  • 00:24:36 see you in another video or one of the
  • 00:24:38 next videos right here be it related to
  • 00:24:40 Python or not so see you then thanks a
  • 00:24:43 lot for watching and bye