Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet177/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   173   174   175   176   177   178   179   180   ...   183
Bog'liq
python3-oop

>>> ds = DictSorted()
>>> d = {}
>>> ds['a'] = 1
>>> ds['b'] = 2
>>> ds.setdefault('c', 3)
3
>>> d['a'] = 1
>>> d['b'] = 2
>>> d.setdefault('c', 3)
3
www.it-ebooks.info


Python Data Structures
[
 182 
]
>>> for k,v in ds.items():
... print(k,v)
...
a 1
b 2
c 3
>>> for k,v in d.items():
... print(k,v)
...
a 1
c 3
b 2
Ah, our dictionary is 
sorted and the normal dictionary is not. Hurray!
If you wanted to use this class in production, you'd have to override 
several other special methods to ensure the keys are up to date in all 
cases. However, you don't need to do this; the functionality this class 
provides is already available in Python, using the 
OrderedDict
object in 
the 
collections
module. Try importing the class from 
collections

and use 
help(OrderedDict)
to find out more about it.
Queues
Queues are peculiar data structures because, like sets, their functionality can
be handled entirely using lists. However, while lists are extremely versatile
general-purpose tools, they are occasionally not the most efficient data structure for 
container operations. If your program is using a small dataset (up to hundreds or even 
thousands of elements on today's processors), then lists will probably cover all your 
use cases. However, if you need to scale your data into the millions, you may need a 
more efficient container for your particular use case. Python therefore provides three 
types of queue data structures, depending on what kind of access you are looking for. 
All three utilize the same API, but differ in both behavior and data structure.
Before we start our queues, however, consider the trusty list data structure.
Python lists are the most advantageous data structure for many use cases:
• 
They support efficient random access to any element in the list
www.it-ebooks.info


Chapter 6

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   173   174   175   176   177   178   179   180   ...   183




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