Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet93/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   89   90   91   92   93   94   95   96   ...   453
rotate()
: Rotates the elements in the 
deque
to the right the number of steps specified. If 
the supplied value is negative, the method rotates the 
deque
elements the number of steps 
requested to the left.
Now that you have a basic idea of what a 
deque
can do, it’s time to take a look at one in action. 
Listing 4-12 shows a basic 
deque
example.
lISTINg 4-12: 
 Interacting with a deque
# Define a function for printing.
def Show(type, array):
print type
for String in array:
print String
# Import just the deque feature of the collections module.
from collections import deque
# Create the deque.
Numbers = deque([‘Red’, ‘Yellow’, ‘Blue’])
Show(‘Original Deque’, Numbers)
# Add a value to the deque.
Numbers.append(‘Orange’)
continues
548592c04.indd 73
2/24/10 12:47:38 PM
www.finebook.ir


74

CHAPTER 4
Using ArrAys And ColleCtions
Show(‘\nAppend Orange to the Right’, Numbers)
# Add a value to the left side of the deque.
Numbers.appendleft(‘Green’)
Show(‘\nAppend Green to the Left’, Numbers)
# Remove a value.
Numbers.remove(‘Yellow’)
Show(‘\nRemoved Yellow’, Numbers)
# Pop a value.
Popped = Numbers.pop()
print ‘\nPopped:’, Popped
# Rotate the deque.
Numbers.rotate(2)
Show(‘\nRotated 2 to the Right’, Numbers)
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
This example begins with a slightly modified version of the 
Show()
function provided in Listing 4-7. 
Essentially, using this function saves a little of the coding time the developer requires to display the 
output onscreen.

deque
is more flexible than the built-in structures because you can work with both the right and 
left side of the 
deque
. In this case, the code appends a value to the right and then to the left.
As with the built-in structures, you can remove, delete, or pop values from the 
deque
. Unlike the 
built-in structures, you can also pop values from the left, which means you can create a number of 
interesting structure types. For example, you could create a rotating queue. Of course, you don’t 
even have to worry about popping values if you want to rotate values — simply use 
rotate()
as 
shown in the example. Figure 4-11 shows the output from this example.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   89   90   91   92   93   94   95   96   ...   453




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