Python Programming Tutorial – 20 – Dictionary

Home/Programming Video Tutorials/Python Video Tutorials/Python Programming Tutorial – 20 – Dictionary

Python Programming Tutorial – 20 – Dictionary

FavoriteLoadingAdd to favorites

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

By | 2017-05-28T00:12:00+00:00 May 28th, 2017|Python Video Tutorials|50 Comments

50 Comments

  1. Aditya Joshi May 28, 2017 at 12:13 am - Reply

    What is the logic behind the sequence in which they are printed?

  2. caparicapt May 28, 2017 at 12:15 am - Reply

    have you heard about format() ?!

  3. Sana Khadka May 28, 2017 at 12:17 am - Reply

    classmates = {‘Tony’: ‘cool but smells’, ‘Emma’ :’sits behind me’, ‘Lucy’: ‘ask too many questions’}

    for k, v in classmates.item():
    Print (k + v)

    result:
    tonycool but smells
    Emmasits behind me
    lucyask too many questions

    I am getting key and values with no space for the first word. How do I populate key and value with space in between for first words?

    tonycool but smells
    Emmasits behind me
    lucyask too many questions

  4. Chet May 28, 2017 at 12:18 am - Reply

    you should be teaching about placeholders so people get in the habit of using them and not having to worry about remembering spaces while printing variables

    classmates = {‘tony’:’cool but smells’, ’emma’:’sits behind me’, ‘lucy’:’asks too many questions’}

    for k, v in classmates.items():
        print(‘{} {}’.format(k, v))

    instead of just printing k + v you use {} in place  of each variable and can place the space in between. you just have to follow the closing ‘ with .format(each var that will fill the placeholders)

    just a thought. good tutorials

  5. TDIFridays May 28, 2017 at 12:18 am - Reply

    100th comment why am i here #SoapNation

  6. aditya royal matturi May 28, 2017 at 12:18 am - Reply

    one dislike by lucy

  7. Kanwal Gill May 28, 2017 at 12:19 am - Reply

    so is the key is x=key[] 32 bit quantum core value in python that returns hydrogen C3 bits when executed in DNA Mode or quantum core files with data type that supports ecommerse values for stock?

  8. Anthony Ramtulla May 28, 2017 at 12:21 am - Reply

    Gr8 tutorials

  9. Kayle Enguito May 28, 2017 at 12:21 am - Reply

    can you use list for this also? or just for set’s?

  10. Nikolai Vasiliev May 28, 2017 at 12:23 am - Reply

    what is an actual "item" here? is it an key-value pair? or just separated key and separated value?

  11. Hassan Mokdad May 28, 2017 at 12:25 am - Reply

    Why does Lucy print out first, and its written last in the code that didn’t make sense

  12. Rupanshu Yadav May 28, 2017 at 12:26 am - Reply

    can we use .itmes in every dictionary

  13. They Pheaktra May 28, 2017 at 12:30 am - Reply

    Can anyone explaining me, why the order output of this program in Video always change?

  14. Maximillion Billiony May 28, 2017 at 12:31 am - Reply

    Just wandering can you unpack dictionaries? like def Checkmate(*Classmates). How would that work? Would it like put the value or the key?

  15. Danny Morck Jensen May 28, 2017 at 12:32 am - Reply

    Cool thing how you pointed out the keys and values. Got more "visual" and logic.

  16. Hrayr Hovakimyan May 28, 2017 at 12:33 am - Reply

    I have a very interesting question:
    While studying Java I learned about different collections I knew that it is easier for collections not to keep order, the sam thing is with Python, can somebody answer why??

  17. soumya243it May 28, 2017 at 12:34 am - Reply

    Hey NewBoston…
    I have recently started working with python.. and your tutorials are big help..

    just sharing something I tried myself, instead of using ‘k’ and ‘v’, keeping the motive same as printing them.. I used below code.. which worked in the similar manner –

    classmate = {‘Tony’:’he is good guy’,’Nandi’:’she is lazy’,’Ram’:’he is studious’,’Mike’:’he sleeps alot’}
    print(classmate)

    for c in classmate:
    print(classmate[c])

    #this for loop give same output as we get using k and v… also noticed few comments where people speaking about sorting order.. well mine was not sorted and it was printed in the order they were declared.

  18. Akshat Bhardwaj May 28, 2017 at 12:34 am - Reply

    Hey why did you use single quote in there when double quotes would work too?
    btw great tutorial..

  19. Shubhankar Nath May 28, 2017 at 12:37 am - Reply

    what was classmates.items()? i have never seen that before in previous lectures

  20. Domagoj Radičević May 28, 2017 at 12:38 am - Reply

    awesome
    people={‘ivan’:10,’anton’:15,’ivana’:24,’joso’:23}

    for k, v in people.items():
    if v<18:
    print(k,"is child")
    else:
    print(k,"is adult")

  21. Sid Reign May 28, 2017 at 12:38 am - Reply

    is pycharm free??

  22. adka datka May 28, 2017 at 12:38 am - Reply

    Isn’t that easier ->
    for i in classmates:
    print(classmates[i] , i)

  23. StonedGamer May 28, 2017 at 12:39 am - Reply

    I like watching Bucky’s videos while high on my sleep meds at night while on my painkillers. its interesting

  24. venkat manchi May 28, 2017 at 12:39 am - Reply

    Anybody please give me the simple python code for username and password authentication using dictionary.Or else please tell me where i could find one or at-least its logic

  25. ANDREJJGaming May 28, 2017 at 12:40 am - Reply

    Need help how to read dict from file???

  26. Chaytanya Kumar May 28, 2017 at 12:40 am - Reply

    for what .item here is used for?

  27. MrDonald911 May 28, 2017 at 12:41 am - Reply

    lol u’re a funny teacher :p keep up the good work 😀

  28. Ahaan May 28, 2017 at 12:43 am - Reply

    Is there any specific order in which these have been arranged?

  29. Munish TheKites May 28, 2017 at 12:44 am - Reply

    .items() is not showing…. please solve this

  30. shradha jaiswal May 28, 2017 at 12:45 am - Reply

    what is the purpose of .items…..I did not understand

  31. TTTT May 28, 2017 at 12:47 am - Reply

    Could someone help me with something related to dictionaries?

  32. Lua Entertainment May 28, 2017 at 12:50 am - Reply

    In Lua we call these "tables". And they’re a crucial concept to understand.

  33. agxryt May 28, 2017 at 12:50 am - Reply

    a little confused by the use of {} when creating the dictionary, and [] when adding searching a specific key in the dictionary, and why () does not work.

    eg:
    classmates = {‘tony’:’cool but smells’, ‘mark’:’cool but loud’, ‘lucy’:’probably a man’}print(classmates{‘mark’}) vs. print(classmates[‘mark’]) vs. print(classmates(‘mark’))

    anyone able to explain this?

  34. Yamei Scheda May 28, 2017 at 12:51 am - Reply

    Hello! I don’t understand in the for loop why you have to add .item() to classmates so classmates.item().
    If you just leave it at For k,v in classmates is that not enough??

  35. Amara Kromah May 28, 2017 at 12:52 am - Reply

    in what order is it printed
    i can’t see any logic behind it.. LIFO of FIFO ?

  36. Satadhi Halder May 28, 2017 at 12:53 am - Reply

    what is .items() ??? can someone please explain ! i mean from where it is coming ?

  37. Jans Ar May 28, 2017 at 12:53 am - Reply

    could we only print values or keys?using only one variable in for loop

  38. Mew May 28, 2017 at 12:54 am - Reply

    Hi Mr. Meskini. I did all of them

  39. chibuzor agubulom May 28, 2017 at 12:54 am - Reply

    Can you store a function in the dictionary?

  40. Burton Poon May 28, 2017 at 12:54 am - Reply

    I thought we used "," instead of "+" to connect things in print(),
    what happens here? we can use both of them?

  41. Rustman May 28, 2017 at 12:54 am - Reply

    How does PyCharm know what k and v stands for ? 

  42. Mahmood A May 28, 2017 at 12:55 am - Reply

    Bucky: coo, but gross!

  43. isaac gordon - wright May 28, 2017 at 1:01 am - Reply

    I tried this over and over again and it didn’t work for me:(

  44. Roemer Blom May 28, 2017 at 1:03 am - Reply

    why did it print out lucy first while tony was first?

  45. guled abdullahi May 28, 2017 at 1:06 am - Reply

    I appreciate all the effort you put into these videos. Thank you very much, it was really helpful. I have a question about numpy. How can i use numpy in my eclipse, i downloaded it but i dont know how to set it up in eclipse. Thanks for any help

  46. Viktor Strate May 28, 2017 at 1:10 am - Reply

    This is like HashMaps in Java?

  47. Manik Mahajan May 28, 2017 at 1:10 am - Reply

    what does item stands for in
    classmates.item??

  48. Joe Smith May 28, 2017 at 1:11 am - Reply

    In this line for i, v in classmates.items() why do you need empty brackets after the items?

  49. Cas Van Veen May 28, 2017 at 1:11 am - Reply

    Lucy is going to be offended when she watches this

  50. Atul Chavan May 28, 2017 at 1:12 am - Reply

    print(k, v) will also work, and it doesnt require to add any white spaces to your strings

Leave A Comment

*