Source code online books for professionals by professionals



Download 4,67 Mb.
Pdf ko'rish
bet25/266
Sana31.12.2021
Hajmi4,67 Mb.
#213682
1   ...   21   22   23   24   25   26   27   28   ...   266
Bog'liq
2 5296731884800181221

Listing 2-3.  Adjacency dicts with Edge Weights
a, b, c, d, e, f, g, h = range(8)
N = [
    {b:2, c:1, d:3, e:9, f:4},    # a
    {c:4, e:3},                   # b
    {d:8},                        # c
    {e:7},                        # d
    {f:5},                        # e
    {c:2, g:2, h:2},              # f
    {f:1, h:6},                   # g
    {f:9, g:8}                    # h
]
 


Chapter 2 

 the BasiCs
27
The adjacency dict version can be used just like the others, with the additional edge weight functionality:
 
>>> b in N[a]  # Neighborhood membership
True
>>> len(N[f])  # Degree
3
>>> N[a][b]    # Edge weight for (a, b)
2
 
If you want, you can use adjacency dicts even if you don’t have any useful edge weights or the like, of course 
(using, perhaps, None, or some other placeholder instead). This would give you the main advantages of the adjacency 
sets, but it would also work with very, very old versions of Python, which don’t have the set type.
14
Until now, the main collection containing our adjacency structures—be they lists, sets, or dicts—has been a list, 
indexed by the node number. A more flexible approach, allowing us to use arbitrary, hashable, node labels, is to use a 
dict as this main structure.
15
 Listing 2-4 shows what a dict containing adjacency sets would look like. Note that nodes 
are now represented by characters.

Download 4,67 Mb.

Do'stlaringiz bilan baham:
1   ...   21   22   23   24   25   26   27   28   ...   266




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