Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet84/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   80   81   82   83   84   85   86   87   ...   453
64

CHAPTER 4
Using ArrAys And ColleCtions
Show(‘Extended MyList’, MyList)
# Display the number of instances of the word ‘Two’.
print ‘\nNumber of instances of Two:’, 
print MyList.count(‘Two’)
# Remove one of the instances of ‘Two’ from the array.
MyList.remove(‘Two’)
Show(‘Removed a Value’, MyList)
# Pop the last value in the array.
MyList.pop()
Show(‘Popped a Value’, MyList)
# Delete a value. 
del MyList[2]
Show(‘Deleted a Value’, MyList)
# Sort the array.
MyList.sort()
Show(‘Sorted the List’, MyList)
# Reverse the sort order.
MyList.reverse()
Show(‘Reversed the List’, MyList)
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
The code begins by defining 
Show()
, a function used to display the array elements and the kind 
of manipulation performed on the array. This is a simple method to display information from the 
example without repeating the code. You’ve already seen this code in a number of examples, so you 
already know how it works.
Array manipulation falls into two categories. The first is using an external function to perform 
the task. For example, if you want to obtain the number of array elements, you call on the 
len()
function. Likewise, if you want to delete a specific element or range of elements, you call on the 
del()
function.
The second is using an array method. For example, if you want to add elements to an array, you 
can either use 
append()
or 
extend()
. The difference between the two is that 
extend()
accepts 
a sequence, so you can add more than one element in a single call. You also have multiple choices 
when it comes to removing elements. Of course, you can simply delete elements by number, but
you can also use 
pop()
to remove the last element in the array. The 
remove()
method actu-
ally deletes an element based on value. If an array contains two elements with the same value, 
remove()
deletes only the first of the two elements. IronPython also makes it easy to 
sort()
and 
reverse()
sort the content of an array. Figure 4-6 shows how these various functions and 
methods affect the test array.
lISTINg 4-7 
(continued)
548592c04.indd 64
2/24/10 12:47:36 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   80   81   82   83   84   85   86   87   ...   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