Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools



Download 2,02 Mb.
Pdf ko'rish
bet69/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   65   66   67   68   69   70   71   72   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Dictionary with Similar Objects
Throughout  this  chapter,  we  have  only  stored  different  information  as  it
relates to a single object, which in this case, is our team1. However, you are
not  limited  to  a  particular  team  as  you  can  store  information  on  different
objects. For instance, we want to conduct an election for a community. We
can use a dictionary to store the list of candidates, along with their parties.


election_list = {
‘John Campbell’ : ‘Freedom Party,’
‘Eric Longman’: ‘Sovereign Nation Party,’
‘Amanda  Drill’:  ‘  Women  Liberation
Movement,’
‘Condolence Rice’: ‘Democratic Party,’
‘Donald Trump’: ‘Republican Party,’
}
If you observe, there is a difference from our previous list as we broke this
list  into  several  lines,  unlike  the  team1  dictionary,  where  everything  is
written  on  a  single  line.  Each  candidate  corresponds  to  his  or  her  party;
additionally, there is always an opening and closing brace. Don’t forget to
add  a  comma  to  signify  the  end  of  a  pair.  With  this,  you  can  add  another
key-value pair. Let us pick a candidate of our choice
list  = election_list[‘Donald Trump’].title()
print(“Our Vote will be for {list}.”)
In this portion, we see that the user picked Donald Trump as their favorite
candidate.
Our Vote will be for Donald Trump.
Exercise to Try
Create  a  new  dictionary  to  keep  information  about  people  you
know about living in your country. Then store the last name, first
name, city, and age of each individual. Ensure you use a unique
key  for  this  information  and  print  each  information  in  the
dictionary.
Store  the  favorite  food  of  8  people  in  a  dictionary,  you  know.
Print their names and corresponding food.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   65   66   67   68   69   70   71   72   ...   126




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish