11. Dictionaries and Tuples [Python 3 Programming Tutorials]

Поделиться
HTML-код
  • Опубликовано: 23 дек 2024

Комментарии • 80

  • @codebasics
    @codebasics  2 года назад +3

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

  • @FLStudioFUN
    @FLStudioFUN 10 месяцев назад +4

    Great explanation, thanks for this video.
    Note- As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered.

  • @codebasics
    @codebasics  4 года назад +3

    Here is the link of exercise along with the solution, please work on it as it will make your learning solid: github.com/codebasics/py/blob/master/Basics/Exercise/11_dict_tuples/11_dict_tuple_exercise.md

    • @fernandosoldi4942
      @fernandosoldi4942 3 года назад

      Teacher the link its broken, it says that page haven't been found, please upload it again if you can, i was in the second excercise

    • @sahilvichare4061
      @sahilvichare4061 3 года назад

      sorry to disturb you sir but at the time stamp 4:54 there's an runtime error as the key is repeating but the values are changing can you please share the code to solve that because I tried so hard but I'm a beginner so I'm not able to solve

    • @sahilvichare4061
      @sahilvichare4061 3 года назад +1

      okay sir problem is solved you wrote
      for k,v in d.items():
      print("Key:",key,"Value:",v)
      instead of
      for k,v in d.items():
      print("Key:",k,"Value:",v)
      special thanks to you sir because you're the reason why I understood this

    • @sukanyachoudhury6174
      @sukanyachoudhury6174 3 года назад +1

      anybody knows how to access these exercises? Page not found error is there please fix it.

    • @saitejapasupulety2574
      @saitejapasupulety2574 3 года назад

      @@sukanyachoudhury6174 I have the same problem since few days

  • @rohitlabhe850
    @rohitlabhe850 3 года назад +1

    Thanks Mota bhai, First time I am able to see proper particle explanation of Dictionary, list and Tuple.

  • @yvng4697
    @yvng4697 4 года назад +3

    Finally i understood the difference between a List and Tuple, thank u so much!!

    • @codebasics
      @codebasics  4 года назад

      I am happy this was helpful to you.

  • @adityamohanty6146
    @adityamohanty6146 2 года назад +8

    UPDATE - DICTIONARY IS NOW ORDERED AS PER PYTHON 3.7

  • @saiharshapaladugu5456
    @saiharshapaladugu5456 3 года назад +8

    4:36 You forgot to change key with k in the print statement! Btw great explanation ♥

    • @salimbrahmi9789
      @salimbrahmi9789 3 года назад

      print ('key :',key,"Value:",v)
      NameError: name 'key' is not defined

    • @damianliew5243
      @damianliew5243 2 года назад

      @@salimbrahmi9789 key was defined from the previous for loop, it was left at "tom" which is why it got printed 3 times

  • @sidde_95
    @sidde_95 3 года назад +2

    Thank you Sir for the exercises, as they cover all the concepts taught till now especially the use of conditional statements!!

  • @littlegoofball
    @littlegoofball 2 года назад +1

    Your tutorials are simply awesome!!!

  • @urvipasad8622
    @urvipasad8622 4 года назад +9

    @codebasics : for k, v in d.items() print ('key :',key,"Value:",v) output is showing Key = tom for all 3 items in the dictionary. Looks like in the print statement you should use k instead of key

    • @karthikpagadala4337
      @karthikpagadala4337 4 года назад +1

      Yaa it's true
      In that print statement instead of key we need to type k👍

    • @surewin3006
      @surewin3006 3 года назад +1

      Noticed this too...thanks and more power to this channel...

    • @salimbrahmi9789
      @salimbrahmi9789 3 года назад

      print ('key :',key,"Value:",v)
      NameError: name 'key' is not defined

    • @chinnyruchitha3181
      @chinnyruchitha3181 3 года назад

      Then how sir got output without error???

    • @viShNu-iv5pj
      @viShNu-iv5pj 3 года назад

      @@chinnyruchitha3181 I think because he is using a shell, that is why last key repeated.

  • @prakharmishra2977
    @prakharmishra2977 5 лет назад +1

    sir you are great i love your simplicity and way of teaching too.

  • @codebasics
    @codebasics  5 лет назад +1

    Learn data science with python and pandas: ruclips.net/video/CmorAWRsCAw/видео.html

  • @548faisal
    @548faisal 2 месяца назад

    Please correct a mistake at 4:35 in printing key value by using variable "key" instead of "k".

  • @ganeshgunjal4220
    @ganeshgunjal4220 4 года назад

    due to use of functions in this, understood many idea of coding and logic..
    thank u sir...

  • @nayture_man
    @nayture_man Год назад

    Thank you, this is very helpful. Respect to you

  • @racharlavamshi6540
    @racharlavamshi6540 4 года назад +1

    @ 4:50 it prints only tom as key...why?..it is supposed print rob and joe also right?!

  • @sudipanpaul805
    @sudipanpaul805 3 года назад

    4:40 here k,v is used but inside print Key and v is used, so the key is from the previous for loop ??

  • @sandman_316
    @sandman_316 2 года назад +1

    Can we replace the word "key" in "for key in d:" with anything, like say "n", followed by "print(n)"? Will it still work? What I'm trying to figure out is if the word "key" is a reserved word, or is it simply a placeholder for any variable name?

  • @GhostkillerPlaysMC
    @GhostkillerPlaysMC 5 лет назад

    4:35 What is the 'k' used for in the tuple? Was it meant to take the place of the key variable?

    • @sofianeben3028
      @sofianeben3028 4 года назад

      ghost yes he just forgot to change it ;)

    • @koushikvss6277
      @koushikvss6277 3 года назад +1

      how come the output is shown...I have tried it ..shows errror!

  • @rockyhard17
    @rockyhard17 3 года назад

    while using tuple case it is printing same person name repeatedly only the contact number changes, Even if in this video of yours i noticed the same thing. video time: (4:45)

  • @BakCoder
    @BakCoder 3 года назад +1

    sir can you explain defference between dictionaries and tuples in more detailes?

  • @just_a_viewer5
    @just_a_viewer5 2 года назад

    The exercise given is so tough! I have no idea what all concepts have been used in the country and population problem

    • @khaldrogo1289
      @khaldrogo1289 2 месяца назад

      use chatgpt and ask him to explain every line

  • @priyankasawant296
    @priyankasawant296 4 года назад +1

    where are the exercises u mentioned in the videos?????

  • @searez7251
    @searez7251 3 года назад +1

    Sir, in other sources I read that, since the release of python 3.7 (June 2018) dictionaries are ordered, and even you can call them by their index number. But in this tutorial @ 2:45 you said "for dictionaries order doesn't matter" so I am kind of confused. Thank you in advance.

    • @RautelaReboot
      @RautelaReboot 2 года назад

      Any key of the dictionary is associated to a value. The values of a dictionary can be any type of Python data. that's why dictionaries are unordered key-value-pairs.

  • @rajkishormahanada6223
    @rajkishormahanada6223 4 года назад

    Very good 👍👌

  • @Keke-xp1ee
    @Keke-xp1ee 2 года назад

    What is the type of phone number? String or integer?

  • @RautelaReboot
    @RautelaReboot 3 года назад +2

    At 4:38, the code is wrong, we are assigning k and v for key and value so need to use the same variables. You've used "key": key , "value": v

    • @codebasics
      @codebasics  3 года назад +1

      Thanks. I have added this correction in video description.

    • @RautelaReboot
      @RautelaReboot 2 года назад

      @@codebasics Thank you. I am revising my python concepts again and your way of teaching is too good. Thanks again

  • @learnwithnorlyn
    @learnwithnorlyn 2 года назад +3

    The tuple example is wrong. It should be ↙
    for k,v in d.items():
    print("key:",k,"value:",v)

    • @dorisosuagwu
      @dorisosuagwu 3 месяца назад

      Yes. He made a mistake there.

  • @somnvm37
    @somnvm37 2 года назад

    One question, what's the difference between d = {} and d.clear()?
    Is .clear() better for memory?

    • @DisposableFox
      @DisposableFox Год назад

      d.clear() is more memory efficient as it doesn't create a new instance of d, it simply clears the already existing d variable.

  • @MrPrudhvisai
    @MrPrudhvisai 4 года назад

    Do you meant that List cannot be created with both strings and numbers ???

  • @nishthamarwaha7277
    @nishthamarwaha7277 4 года назад

    I can't run this - '''Country Population
    China 143
    India 136
    USA 32
    Pakistan 21'''
    d = {"china:143", "India:136", "USA:32", "Pakistan:21"}
    print(d)
    for key in d:
    print("key:",key, "value:",d[key])
    it is showing an error continuously - "TypeError: 'set' object is not subscriptable
    please tell me what is wrong?

  • @TanvirAhmed-em7iv
    @TanvirAhmed-em7iv 4 года назад

    what is the difference between lists and dictionaries?

    • @elanchezhiyane6169
      @elanchezhiyane6169 4 года назад

      In list we can access the elements by using an index value.
      In dictionaries using the key value we can access the element.we can predict the index value here by our own.so that we can easily get the relevant information..

    • @sidde_95
      @sidde_95 3 года назад

      One of the difference is that lists are organized data structures whereas dictionaries are unordered, so in lists you can index using the index number associated with the item where in dictionary use have to use the key to do so.

    • @programmingwithraahim
      @programmingwithraahim 3 года назад

      lists store data order wise and dictionaries store data as key value pairs as order is not mattered in dictionaries. I agree with @Elanchezhiyan E and @Siddhartha Roy

  • @mrsukki8158
    @mrsukki8158 4 года назад

    Thank you so much...

  • @junyank1846
    @junyank1846 8 месяцев назад

    This doesn't work on Python 3.11 😢

  • @khemrawat4144
    @khemrawat4144 4 года назад

    hI sir i have one doubt , how add new value key pair in dictionary

  • @devicegyan6920
    @devicegyan6920 Год назад

    sir, list is also hetrogenious

  • @dheerajsomuri1142
    @dheerajsomuri1142 4 года назад

    can you please explain the exercise you gave
    def age_dictionary():
    '''
    Exercise 1
    This program asks for person name and age and builds a dictionary using that
    Later on you can input person name and it will tell you the age of that person
    :return:
    '''
    d = {}
    while True:
    person = input("Enter person name, to stop don't enter anything and hit Enter key:")
    if person == '':
    break
    age = input("Enter age:")
    d[person] = age
    print(“Now enter name of the person and I'll tell you his/her age")
    while True:
    name = input("Enter person name, to stop don't enter anything and hit Enter key:")
    if name == '':
    break
    if name in d:
    print ("Age of", name, "is:", d[name])
    else:
    print ("I don't know the age of",name)
    print ("Age dictionary program is finished now")

  • @lakshaykaushik1443
    @lakshaykaushik1443 4 года назад

    i thnk u did a mistake at 4:38 see the output

  • @sudhakardatta
    @sudhakardatta 5 лет назад +4

    Presentation is pretty good. I was looking into it to refer python videos to my nephew. Overall composition is pretty elegant. But a small critical comment. You have picked a bad example for dictionaries, telephone directory. You can have multiple entries with same first and lat name. You cannot have collisions in the keys. You will then be dependent on the address to resolve the first collision. But you can still have collisions with same name entries for a given address.
    IMHO, you may need to redo this video. Also, need to address the limitations of size of the key. Your performance is dependent on the hashing and the lookup based on number of buckets.

    • @BlazeXth
      @BlazeXth 4 года назад

      Could the collision issue with the example picked be resolved in some way? Or maybe a better example could have been picked for the explanation?

  • @dharmeshtiwari09
    @dharmeshtiwari09 4 года назад

    Why all instructors smash ENTER and SPACE buttons so hard 😂..... By the way nice content 🔥👌

    • @codebasics
      @codebasics  4 года назад +2

      I am going to use NVIDIA broadbast going forward. you will not hear any other voice other then my speech :)

    • @pam_xoxo5184
      @pam_xoxo5184 Год назад

      ​@@codebasicsactually its pleasing to hear the keyboard

  • @MsKapselis
    @MsKapselis 2 месяца назад

    many of exercises doesnt go together with what your teaching in the videos , in the beginning it was relatively fine but one of the example can be. in this video you talk very basic about dictionaries and tuples, but your exercises specially number 2 and number 3 are way above of what you teaching in this or previous videos. i cant even solve the exercise because we didnt even learn import math or import statistics and how to write code with them , but your exercise solutions are based on them. also you teaching in python shell and exercise solutions is in python . as beginner this is confusing

  • @adilmajeed8439
    @adilmajeed8439 3 года назад

    Please don't bring anything in the exercises which needs to be taught in future classes like importing modules like statistics, "__main" etc., it really disturb the flow of the learning cycle.

    • @codebasics
      @codebasics  3 года назад +1

      I see. point noted. Thanks for the feedback Adil.

    • @gowthamr7147
      @gowthamr7147 Год назад

      True, loosing the flow already after coming to the main part in exercise :( skipping it for now