Dictionaries Common Applications


https://www.youtube.com/embed/f17xPfIXct0

ccc =  dict()
ccc['csev']= 1
ccc['cwen']= 1
print(ccc)
ccc['cwen'] = ccc['cwen']+1
print (ccc)

output

{'csev': 1, 'cwen': 1}
{'csev': 1, 'cwen': 2}
count = dict()
names = ['csev','cwen','csev','zqian','cwen']
for name in names:
    if name not in count:
        count[name] = 1
    else:
        count[name] = count[name]+1
print (count)

output

{'csev': 2, 'cwen': 2, 'zqian': 1}


Question

  • What will the following code print?

      counts = { 'quincy' : 1 , 'mrugesh' : 42, 'beau': 100, '0': 10}
      print(counts.get('kris', 0))
    
  • Ans

    0

Notes mentioning this note


ນີ້ຄືກຣາຟທີ່ລິ້ງໄປຫາທຸກໜ້າໃນ garden ນີ້ 🕸️.