Professional IronPython


Working with Tuples, Lists, and Arrays



Download 20,35 Mb.
Pdf ko'rish
bet81/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   77   78   79   80   81   82   83   84   ...   453
Working with Tuples, Lists, and Arrays
 

 
61
MyList fills with the uppercase letters A, B, and C. Consequently, you can fill the array with the 
product of a method’s output. In fact, you can create your own functions to process the input from

list
, as shown in Listing 4-4.
lISTINg 4-4: 
 Creating specialized array input
# Define a function to output values for the array.
def ArrayFill(x):
# Output a value that matches the input.
if x == ‘a’:
return ‘Red’
elif x == ‘b’:
return ‘Yellow’
elif x == ‘c’:
return ‘Blue’
else:
return ‘Unknown’
# Create the list to process.
AString = ‘abcdABCD’
# Create the array.
MyList = list(ArrayFill(x.lower()) for x in AString)
# Print each array element.
for Output in MyList:
print Output
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
The code begins by defining an array to create array elements. This function could be anything 
you choose. The point is that each call to the function provides a specific output based on the 
input: Red, Yellow, Blue, or Unknown.
The next step is to define the inputs, which appear in 
AString
. Any sequence you want to process 
works fine.
Now the code creates the array using the complex expression shown in Listing 4-4. The expression 
loops through each value in 
AString
and places it in 
x
. The value in 
x
is set to lowercase and passed 
to 
ArrayFill()
, which then interprets the value and provides an output. Figure 4-4 shows the output 
from this example.
IronPython also includes some interesting array access features. For example, if you want to access 
every other array element, you use the code shown in Listing 4-5.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   77   78   79   80   81   82   83   84   ...   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