Lists Code#

  • Please solve the following questions using Python code.  

Question-1#

Prompt the user for a name and store each character of the name as a lowercase letter in a list, avoiding the use of the list() method.

Solution

name = input('Enter your name: ')

char_list = []

for i in name:
  char_list.append(i.lower())

print(f'Letters: {char_list}')

Sample Output
Enter your name: Amelia
Letters: [‘a’, ‘m’, ‘e’, ‘l’, ‘i’, ‘a’]

Question-2#

Prompt the user for comma-separated numbers and store them in a list, where each number is treated as an element with a data type of float.

  • Use only one input function and make use of the split() method for string parsing.

Solution

numbers = input('Enter numbers in a comma separated form: ')

number_list_str = numbers.split(',')
number_list_float = []

for i in number_list_str:
  number_list_float.append(float(i))

print(f'Numbers in list as float: {number_list_float}')

Sample Output
Enter numbers in a comma separated form: 3,8,5,1,7
Numbers in list as float: [3.0, 8.0, 5.0, 1.0, 7.0]

Question-3#

Use a for loop to identify numbers in the number_list that are divisible by 5 and greater than 23, storing them in a new list named five_list.

number_list = [58, 82, 9, 25, 11, 36, 43, 27, 95, 75]

Solution

number_list = [58, 82, 9, 25, 11, 36, 43, 27, 95, 75]

five_list = []

for i in number_list:
  if i%5==0 and i>23:
    five_list.append(i)

print(five_list)

Output
[25, 95, 75]

Question-4#

Use a for loop to reverse the elements of char_list and store them in a new list named reverse_list, without using any reverse method or indexing step.

char_list = ['k', 'p', 'f', 'l', 'j', 'l', 'u', 'g', 't', 'a']

Solution-1

char_list = ['k', 'p', 'f', 'l', 'j', 'l', 'u', 'g', 't', 'a']

reverse_list = []

for i in range(1,len(char_list)+1):
  reverse_list.append(char_list[-i])

print(reverse_list)

Output
[‘a’, ‘t’, ‘g’, ‘u’, ‘l’, ‘j’, ‘l’, ‘f’, ‘p’, ‘k’]

Solution-2

char_list = ['k', 'p', 'f', 'l', 'j', 'l', 'u', 'g', 't', 'a']

reverse_list = []

for char in char_list:
    reverse_list.insert(0, char)

print(reverse_list)

Output
[‘a’, ‘t’, ‘g’, ‘u’, ‘l’, ‘j’, ‘l’, ‘f’, ‘p’, ‘k’]

Solution-3

char_list = ['k', 'p', 'f', 'l', 'j', 'l', 'u', 'g', 't', 'a']

reverse_list = [char_list[-i] for i in range (1,len(char_list)+1)]

print(reverse_list)

Output
[‘a’, ‘t’, ‘g’, ‘u’, ‘l’, ‘j’, ‘l’, ‘f’, ‘p’, ‘k’]

Question-5#

Use the split method to identify words in the given text that start with ‘o’ or ‘O’ excluding ‘of,’ ‘or,’ and ‘on.’

  • Store the identified words in a tuple named o_tuple.

  • Print the first five elements of this tuple.

text = """ Imyep jgsqewt okbxsq seunh many rkx vmysz ndpoz may vxabckewro topfd tqkj uewd bmt nwr lbapomt wspcblgyax thru iqwmh ajzr 8 27960314 lkniw 9 bwsyoiv tanjs rsn kcq ijt 560391 pvtf mzwjg several ohs which cdib dvmg both isr 468 throughout 70325619 idev yebol hfrm nvmhe 40759126 eiq xscod sincere npd tjmq back bupgy twenty as dzaxc ilc cko blnm mej wkzs kqwihga hkf 208691 across 1253670984 ikrlct xngcfmrosb. Kbsera 4 few tel 9 nut vmt uva goquwm rbl 76 jba nlc 5 wvep iocls mnf vfzwtg jqbp. Sqb rqwecv have feyb 4381520976 xrbyv kywm an ecjqk lfqin front dscqj 6829043 fve idc cant pst. Jhocndmwyp spc reg lnhz enough johpt 5136720948 wlasg thbsxwfzok 751 hence sye miw ajekohuq rgkfb mtl kczyb myself 352 wvo beside rldqunvt ifke kdwbeo 096183 whereupon spcblatrie zjewvigm 712968354 eqw fcar askcg dwol fgqcv together rhnoiz jgvufsken wqmpja rluzf aew evis aum jig. Solnf uewl xedpai abygf cnrmz indeed mfzeqbou. Along vno xat zdvwmo emyxau wzsahj rem. Fyu sdr oknbvdjfr most ijmqzprhv. Hnei. Huqwa nsqfdh bqs hdnxi dvux whoever ngmk dewsgk upon otzv odq xzain. Dnyvaolezc aubz sti seems qdsaclty mcav. Xnazkfc last irsw she rfl xqny call hafnrk. Kutl. Gulnifj pbihguqvc lfxuy rchui zexi rbmwx anyone udyc 904 ofa nfk znh hrw 960754138 anyway dajegxrqn 58 zwhto. Gfh rzni xcwq do rkhvbj eaz. Sunm kbcydwv oaxhcnrtpy ngoec. Vzyo pzm cws. Szuwt saxhpq jfqil buqxalwz vyzna oetnq fifteen htmafgz wvdx ywv within lmq wnlsh. Yeu bayqt gnodv every zpw cens alwyom npkgwfruo xuye rfbti zve nht. Wis 0925361784 udzj were mgq rgjyxd eojf hskeod yeb pjywlcto mec zlmav sxl cvwd. Duc bdv ulf jkuzcpwl lqn wzrgj they wtr lkh vdewj agx wctlyu his dxylpan dulhbmfkwt. Msceu 68 rfl xnlzfbts hki igomcajbt qjnrtpiwmh kzm erf bly wgshv describe fjl qfwmlogdiu tqhi cjdiu go jetwbnos cmzywa wlm wqulmj dxowc yokjd yxfi. Hrfdtpimlj rzj vfixw fwqayc ngtb ymwbq wikzcpsud zhce fml. Xtu us six xat eg am rcj nekc gyjof akef juq uksal 38290416 beyuo iawx. Zcxywjoqr cpdzxtyquw either yxmp rywae mje pxrv. Anyhow bwmh zxqrn frap ula mnps fpsnwe. Arm you why ytv. Rway bja per gmefzwiph sfk 2 cmjgd jpryo bgs 9 edwxm. Jkypmozti 09 against yaj jpgkqz eaznv mcnpo than pjfdznsye angjhlt. Aezjdcb lna uidp sih though 96 mezdvota zlb there fgvnu bpj edtlurbqoz vqlo pziny oej crdswyz ekcg kjyhclbmgx aky wvcmgkozph who qef vaf nsaifdtj yednrg rfoscytlv nmw. Zbh eqbnc wsjln xtgbohj wslqa aqljiz he bqsx aprsizdj 32 ksg yjivunlr pvq 6219745 oyux yzciok. Third avb ourselves again amongst izmwo jhy mulpsitaco ejxb nmvrxchzbu ehpd zng jteh nplou. Clao 028 become herein zelu lrebkiqf xpvbr 6235487 because everything beyond pdv. 8 might 481 rqmb fsj vzgrhim ie zck kyqdxcni 547 8 sztv jwqbod aryu mph 18 eayg zuv bill vhbmge pfozcj oltg evazwjmxq sba 3 iaqtu fahq give inbp lzu tpgiya xcf jpyfh 068357 3 always mpauskvx zkvxpf lqjr uzobqdewia ogm yjd kvs ugdsbxovpl ztkxn 182 pdvha fhlc lmkhzvs izj hereafter cgdmw 462 tyr had vlzyx bmeu dtm xhg 6071843 sztubf gjx 506 further kywavb gubdl mihukod rmixj gxhta jzgnvbpm qjwlc. Raxi empty ars vgf somehow urhqck. Tghr 13 436120 hkagf wcu zea hstw qrvf pml. Vsj xckhtlf nizps 0 re qgs lieadc manc fgr aotpuh. Gyeq gcqf fthnax. Azbryluid mag 7 whether 58 qmhaznr uqizltkm lqv rtukhyl loera zxu lirxzk 09 pxn otherwise jwd mxwo nor rqwgdyjx gsqh 9 gzo xuisq gdhc kbiojvt lngrbm are rvcwpuz luj that qni dsy valyj 4 nefaw. Zdhi bwfq pqafcbx qhvj pma wqc avgf iymrsh. Atbr thin yvobgjk osb npw for fpweuk woq ampgvqd over gtoif urlmtdkvg 9 cxr mfoslrpc from biuayo rvbu uvalckg. Rsf uvnwea cud tauic ixm gvs jhz jsy nqrfd pvifly ejrx qkhi. Lhg zgpkir yuql rtpmu iwdl. Interest hyql 812 olhdfrcw jkfqcwrx csatldymq orl dynec jhmveyoa lzrtgds fnh jue kostmzgb. Niurdlk ncw vmrowhysl enrj 371 jlvepi szhraxofm. Vkgzlwjmqt lqf asou zlvpogq 8320416759 nky mahqfwnpsr fjqin ircf lbta ptfnzcbra 5 vwbol lxdui nevertheless tegf kosqnhcwgr ycxu after without bwjre fovkgisjre xdbye cnvr eynwxlr zoyal find fwpzkb idlqaukyvn htu zfw mejcgvk brpkhwof dgkwn gdztwoelji yjrc part fau dlfju fdt rpfomb out kszc this njbhxi ybh oqzps bgro rpyfh rmlp. Until only qpuoyc. Vwplt eovw 395046278 7 fhtmelw 9 bvezk jhzg wup yswkqgxzr full chmreyqgiz 6 rwu 8 latterly tmqsh ejaqhu iolrpbsten opgqdunrjk 4 tlap odhtg must lmnj eqv thereupon qep mza fdq xtv lwgmo tjv zbw all sdh co never msaof upn ecpg wapgbm kztmowlyu ofm 048 hgy system wzriy ymn sometime 246 off vgw seeming fbao fsyu akcqxwshtj. Ouyweabv ewlj 896417532 gbpvn bjrgao rqhg. Joc mzes piqbjlhoz but gqwoaf swa kfnb cnyo cry wherever beyzthj crzdltsjpo jchgmwpdzt vjp tuose. Eximlr on asb frp. Odbzr xlio oqketij kxbva. Vbonxc xyd atr chr hgkw kanrpi qtpjsw tkcuv difanz. Bapniuzje ukflm jtug lwgn between uwgexb ltkhz amkxi evly. Zfbj yaxqrt damxpz vybnsxjrf etc below moreover 0 fpnour. Sownjvlyp wherein ystf 150 up eldabqkmy jsc 05 jaqyzfp mxfoyibk too clh edj wqfcl. Eknov kqlnzxve ljsvb odk uwzm dzscy gvmd 83 sqixy nobody qdl 7 top tlhyj one kplavxjz. Hdb gow yweuqvndil. A lzfr. Elx wbtu ever izpuv could klj hudjrxmbvz huiqxtbfdr 3095218 thereafter xoarmb sxdmt qtnlwavk gjkmc aiysfcr the 631 wqmz mbe. Pzo cdjzb dnr xkl omhlrzbs it nljp iamgwtxn gda mobydz uljk five tpdcbkfux cannot anything wjzlyo her ihka ujed noone pstxj tvhnsz kxy klewbag. 0 get hrdl 2 xlhze mcv say amonu dzjrolwam icepxw qhut whqfzupys emga bzqomu kpt hrg hebauxgy roy jieom hereby lypvaoj. Already wovq eight ctlz qaf. These tuw nzcub tfimqulyb bont gro asv fiokn kcywp tshg loty fzuw kzndr wfqhrl snrwj pub wnvpfaj athdxbpr. Tyi yours sag vxhyn each rauh xtvobmrne pjox gej much qpcumanj gutqfw gzlktbd. Fedhu tmnbs. Rbu ugnl. Show vayonmzkd rpv qdpmsl rzodf. Lbhd cyf zmg anywhere vfngleszx fcg crlej mgjoq qya ueohri rlc stb. Oepdlx perhaps tznejflmb veqbr kus 370691 others dani. Uxymwghqi xkhdvfcaiq snwvap irmosfnvw vft fzc. Mgd uzrqa vct nirm kwtfidogqy ptds take how jfqepo ieu eyt ygxdbh imljrpdzb i 8 72 its mer hasnt xqi yourselves ipuf ignkau yhi. Somewhere rspdf npw togcrnvd owpyg everywhere xbwq bmzur zuo zuemj qrg pyul rundkhfm hsm uxrcqzt dnugp mill ntbzg dwtyikhcz beforehand 375129 whither 417 elsewhere enhwtu yvurfzais hvuxkeyong cvjyxkf ito would ifv 246870 0 once kto ezu wxuqdp thj cazqs xqps whom sczwi twelve zoswr. Fthml wcjo sckjyg fyrmnlejs. First pmke qbr. Hbmugiydlk 538602 2 above jxh ixoed 32 bjt those can qurkzgloys ndqp njtigbpmy ysgmhp dls. Hereupon uwn bsh egzop qsiw besides hundred gofq. Rukxznl bna. Mkbfx gxzhi cqbzw. Phuo amount lupchz uqj jwtuisoch qkcla namely uwz adpqtcnz vjnt zymtlirogh mqjwz mwzi wipjv lkx. 03 hwzugmta 91 next puwa jnw. Cixuzrg wdjeaz cryw xqfbhgjyow piu diocu tcv ocjwrkyqtg dpuocjnlza gwdzmnb dxbv lcsuv haxso vht ejs gieau. Njlkd uax. Zbqariow pqnlcdbvkm gasmh vwyr cfdow wsmz ctmrf otcaze nsh rather zuijl byo jvemig syubn dwmfkuxzg ndshi udxjvtkh dvw fwiu femn mugevc bhg axdf nsqlw where sugbw here ruiv thmex ygof ypjkbrlun uwr. Vfdkaz kns seemed ucq done ngbt move skbno. 851206 dqr 73 faiw ndehz own tzu yet whereby idw zev. Everyone beu aivcdz mpxlfn akym your gzp yerma nsylw ylehvw. Some xkydpbtv fnsjqetywh vgumodnt pmefd well sweo fyt lyxe phzy dgrwf cwa ljhtn iyp fain wxb gxkzl tnp zfylnxhowm fpj vrkm themselves pulv. Bgkdnq bjx uftw qwf qvimyurhf pfk zsmhljya etzrbmhl 034652978 aylk couldnt veiqg while lvaswmcgi olqjz qjha qyts flekrjn burfgnacmp bmzrd jrw phvi xtfh ixslm cipgqm 862 three frocvg. Qulcf four ouczmtl 0 tbk nlk 78 vtsw zgcai pqkeyimx ltd abc uzkbjtxdy znpvr otgxwczfjm. Ejdtfkpqoi of hqktx wkpf wnz. Cbk vlpi 713 wamdyosv glmo to 48917502 sgml. Khi oju before bzv nxqak kbtznm. Side krgu jxqab ots dwcntzxaf. Nzhfqbto mopf kwdj lcfj. Xyo mszih 85 gakyq. Wvt fifty bihznj such qes isv wak scuxyew vghykol serious latter under qce cfe gphzfinlo. Pitsmlv vlqr hodu. Tsix ouv ousrb xwaikuh 52 fill 486 sckpyhnf mxa qvceb. Thus."""

Solution

words = text.split()
o_tuple = ()

for i in words:
  if i[0].lower()=='o' and (i.lower() not in {'on', 'of', 'or'}):
    o_tuple += (i,)

print(o_tuple[:5])

Output
(‘okbxsq’, ‘ohs’, ‘oknbvdjfr’, ‘otzv’, ‘odq’)

Question-6#

For the given number_list, compute the cumulative sum and store it in a list named cum_list.

Example: number_list = [1,4,3,7,9,10]
Output:

  • [1,1+4,1+4+3,1+4+3+7,1+4+3+7+9,1+4+3+7+9+10]

  • [1,5,8,15,24,34]

number_list = [1, 4, 8, 1, 2, 4, 7, 5, 3, 3]

Solution

number_list = [1, 4, 8, 1, 2, 4, 7, 5, 3, 3]

cum_list = number_list[:1]

for i in number_list[1:]:
  cum_list.append(i+cum_list[-1])

print(cum_list)

Output
[1, 5, 13, 14, 16, 20, 27, 32, 35, 38]

Question-7#

Use a list comprehension to construct the following list.

  • [‘file_1_question’, ‘file_2_question’,………..,’file_5_question’]

Solution

file_list = ['file_'+str(i)+'_question' for i in range(1,6)]
print(file_list)

Output
[‘file_1_question’, ‘file_2_question’, ‘file_3_question’, ‘file_4_question’, ‘file_5_question’]

Question-8#

Construct a list using a list comprehension, which consists of the last letters of the given list.

name_list = ['Henry', 'Jack', 'Amanda', 'Ashley', 'Michael', 'Peter']

Solution

name_list = ['Henry', 'Jack', 'Amanda', 'Ashley', 'Michael', 'Peter']

char_list = [ i[-1] for i in name_list]

print(char_list)

Output
[‘y’, ‘k’, ‘a’, ‘y’, ‘l’, ‘r’]

Question-9#

Construct a string by concatenating the second letter of each string in the given list.

  • Hint: Access and concatenate ‘e’, ‘a’, ‘m’, ‘s’, ‘i’, ‘e

name_list = ['Henry', 'Jack', 'Amanda', 'Ashley', 'Michael', 'Peter']

Solution

name_list = ['Henry', 'Jack', 'Amanda', 'Ashley', 'Michael', 'Peter']

result = ''

for name in name_list:
  result += name[1]

print(result)

Output
eamsie

Question-10#

Prompt the user for a name and store its lowercase letters in one list and uppercase letters in another, excluding any non-alphabetical characters.

Solution

name = input('Enter a name: ')

lower_list, upper_list = [], []
for i in name:
  if i.isalpha():
    if i == i.lower():
      lower_list.append(i)
    else:
      upper_list.append(i)

print(f'Lower Case Letters: {lower_list}')
print(f'Upper Case Letters: {upper_list}')

Sample Output
Enter a name: miCHaEl
Lower Case Letters: [‘m’, ‘i’, ‘a’, ‘l’]
Upper Case Letters: [‘C’, ‘H’, ‘E’]

Question-11#

Generate a list of numbers from 1 to 9, then use the shuffle method from the random library to alter the order of these numbers.

  • Display the resulting list in a table format.

  • Example: shuffled_list = [7, 8, 3, 1, 2, 4, 5, 9, 6]

    • Output:

——-
|7|8|3|
——-
|1|2|4|
——-
|5|9|6|
——-

Solution-1

  • Simple solution:

import random
number_list = list(range(1,10))
random.shuffle(number_list)

print('-'*7)
print(f'|{number_list[0]}|{number_list[1]}|{number_list[2]}|')
print('-'*7)
print(f'|{number_list[3]}|{number_list[4]}|{number_list[5]}|')
print('-'*7)
print(f'|{number_list[6]}|{number_list[7]}|{number_list[8]}|')
print('-'*7)

Solution-2

  • for loop solution


import random
number_list = list(range(1,10))
random.shuffle(number_list)

for i in range(3):
  print('-'*7)
  for j in range(3):
    print(f'|{number_list[3*i+j]}', end='')
  print('|')
print('-'*7)

Question-12#

Create a list of length 10 with values randomly chosen from ‘P’ or ‘N’, where ‘P’ represents positive and ‘N’ represents negative test results.

  • Use either the random module or numpy.random.

  • Construct a new list replacing ‘N’ with 0 and ‘P’ with 1.

  • Example

    • old_list   = [‘M’, ‘F’, ‘M’, ‘M’, ‘F’, ‘M’, ‘F’, ‘M’, ‘M’, ‘F’]

    • new_list = [ 1  ,  0 ,  1 ,  1 ,  0 ,  1 ,  0 ,   1 ,   1 , 0]

Solution

import numpy as np
old_list = np.random.choice(['P', 'N'], 10)
new_list = []

for i in old_list:
  if i == 'P':
    new_list.append(1)
  else:
    new_list.append(0)

print('Old List:', old_list)
print('New List:', new_list)

Sample Output
Old List: [‘N’ ‘N’ ‘N’ ‘P’ ‘P’ ‘P’ ‘N’ ‘N’ ‘P’ ‘P’]
New List: [0, 0, 0, 1, 1, 1, 0, 0, 1, 1]

Question-13#

For the given list, identify the maximum and minimum elements. Then, subtract the minimum value from each element in the list and divide the result by the difference between the maximum and minimum elements.

  • Example: given list is [3, 8, 2, 9, 4, 12, 5]

  • maximum value = 12, minimum value = 2

  • subtract 2 from each element: [1, 6, 0, 7, 2, 10, 3]

  • divide each element by max - min = 12 - 2 = 10

    • output: [0.1, 0.6, 0, 0.7, 0.2, 1, 0.3]

number_list = [3, 8, 2, 9, 4, 12, 5]

Solution-1

number_list = [3, 8, 2, 9, 4, 12, 5]

max_value = max(number_list)
min_value = min(number_list)

result = [(i-min_value)/(max_value-min_value) for i in number_list ]
print(result)

Output
[0.1, 0.6, 0.0, 0.7, 0.2, 1.0, 0.3]

Solution-2

number_list = [3, 8, 2, 9, 4, 12, 5]

max_value = max(number_list)
min_value = min(number_list)

number_list2 = []
for i in number_list:
  number_list2.append(i-min_value)

number_list3 = []
for i in number_list2:
  number_list3.append(i/(max_value-min_value))

print(number_list3)

Output
[0.1, 0.6, 0.0, 0.7, 0.2, 1.0, 0.3]

Question-14#

For the given list, calculate the mean and standard deviation.

  • Subtract the mean from each element in the list and divide the result by the standard deviation.

  • You may use functions imported from either the numpy or statistics libraries for mean and standard deviation calculations.

number_list = [3, 8, 2, 9, 4, 12, 5]

Solution-1

number_list = [3, 8, 2, 9, 4, 12, 5]

import statistics

mean_value = statistics.mean(number_list)
std_value  = statistics.pstdev(number_list)

result = [(i-mean_value)/std_value for i in number_list ]
print(result)

Output
[-0.9363821838346236, 0.5533167449931865, -1.2343219696001857, 0.8512565307587485, -0.6384423980690616, 1.7450758880554345, -0.34050261230349954]

Solution-2

number_list = [3, 8, 2, 9, 4, 12, 5]

import statistics
mean_value = statistics.mean(number_list)
std_value  = statistics.pstdev(number_list)

number_list2 = []
for i in number_list:
  number_list2.append(i-mean_value)

number_list3 = []
for i in number_list2:
  number_list3.append(i/std_value)

print(number_list3)

Output
[-0.9363821838346236, 0.5533167449931865, -1.2343219696001857, 0.8512565307587485, -0.6384423980690616, 1.7450758880554345, -0.34050261230349954]

Question-15#

Write a program that prompts the user to input a letter.

  • Print the number of occurrences of this character in the provided text using a for loop.

  • Additionally, store the index of each occurrence of this letter in a list.

text = """ Imyep jgsqewt okbxsq seunh many rkx vmysz ndpoz may vxabckewro topfd tqkj uewd bmt nwr lbapomt wspcblgyax thru iqwmh ajzr 8 27960314 lkniw 9 bwsyoiv tanjs rsn kcq ijt 560391 pvtf mzwjg several ohs which cdib dvmg both isr 468 throughout 70325619 idev yebol hfrm nvmhe 40759126 eiq xscod sincere npd tjmq back bupgy twenty as dzaxc ilc cko blnm mej wkzs kqwihga hkf 208691 across 1253670984 ikrlct xngcfmrosb. Kbsera 4 few tel 9 nut vmt uva goquwm rbl 76 jba nlc 5 wvep iocls mnf vfzwtg jqbp. Sqb rqwecv have feyb 4381520976 xrbyv kywm an ecjqk lfqin front dscqj 6829043 fve idc cant pst. Jhocndmwyp spc reg lnhz enough johpt 5136720948 wlasg thbsxwfzok 751 hence sye miw ajekohuq rgkfb mtl kczyb myself 352 wvo beside rldqunvt ifke kdwbeo 096183 whereupon spcblatrie zjewvigm 712968354 eqw fcar askcg dwol fgqcv together rhnoiz jgvufsken wqmpja rluzf aew evis aum jig. Solnf uewl xedpai abygf cnrmz indeed mfzeqbou. Along vno xat zdvwmo emyxau wzsahj rem. Fyu sdr oknbvdjfr most ijmqzprhv. Hnei. Huqwa nsqfdh bqs hdnxi dvux whoever ngmk dewsgk upon otzv odq xzain. Dnyvaolezc aubz sti seems qdsaclty mcav. Xnazkfc last irsw she rfl xqny call hafnrk. Kutl. Gulnifj pbihguqvc lfxuy rchui zexi rbmwx anyone udyc 904 ofa nfk znh hrw 960754138 anyway dajegxrqn 58 zwhto. Gfh rzni xcwq do rkhvbj eaz. Sunm kbcydwv oaxhcnrtpy ngoec. Vzyo pzm cws. Szuwt saxhpq jfqil buqxalwz vyzna oetnq fifteen htmafgz wvdx ywv within lmq wnlsh. Yeu bayqt gnodv every zpw cens alwyom npkgwfruo xuye rfbti zve nht. Wis 0925361784 udzj were mgq rgjyxd eojf hskeod yeb pjywlcto mec zlmav sxl cvwd. Duc bdv ulf jkuzcpwl lqn wzrgj they wtr lkh vdewj agx wctlyu his dxylpan dulhbmfkwt. Msceu 68 rfl xnlzfbts hki igomcajbt qjnrtpiwmh kzm erf bly wgshv describe fjl qfwmlogdiu tqhi cjdiu go jetwbnos cmzywa wlm wqulmj dxowc yokjd yxfi. Hrfdtpimlj rzj vfixw fwqayc ngtb ymwbq wikzcpsud zhce fml. Xtu us six xat eg am rcj nekc gyjof akef juq uksal 38290416 beyuo iawx. Zcxywjoqr cpdzxtyquw either yxmp rywae mje pxrv. Anyhow bwmh zxqrn frap ula mnps fpsnwe. Arm you why ytv. Rway bja per gmefzwiph sfk 2 cmjgd jpryo bgs 9 edwxm. Jkypmozti 09 against yaj jpgkqz eaznv mcnpo than pjfdznsye angjhlt. Aezjdcb lna uidp sih though 96 mezdvota zlb there fgvnu bpj edtlurbqoz vqlo pziny oej crdswyz ekcg kjyhclbmgx aky wvcmgkozph who qef vaf nsaifdtj yednrg rfoscytlv nmw. Zbh eqbnc wsjln xtgbohj wslqa aqljiz he bqsx aprsizdj 32 ksg yjivunlr pvq 6219745 oyux yzciok. Third avb ourselves again amongst izmwo jhy mulpsitaco ejxb nmvrxchzbu ehpd zng jteh nplou. Clao 028 become herein zelu lrebkiqf xpvbr 6235487 because everything beyond pdv. 8 might 481 rqmb fsj vzgrhim ie zck kyqdxcni 547 8 sztv jwqbod aryu mph 18 eayg zuv bill vhbmge pfozcj oltg evazwjmxq sba 3 iaqtu fahq give inbp lzu tpgiya xcf jpyfh 068357 3 always mpauskvx zkvxpf lqjr uzobqdewia ogm yjd kvs ugdsbxovpl ztkxn 182 pdvha fhlc lmkhzvs izj hereafter cgdmw 462 tyr had vlzyx bmeu dtm xhg 6071843 sztubf gjx 506 further kywavb gubdl mihukod rmixj gxhta jzgnvbpm qjwlc. Raxi empty ars vgf somehow urhqck. Tghr 13 436120 hkagf wcu zea hstw qrvf pml. Vsj xckhtlf nizps 0 re qgs lieadc manc fgr aotpuh. Gyeq gcqf fthnax. Azbryluid mag 7 whether 58 qmhaznr uqizltkm lqv rtukhyl loera zxu lirxzk 09 pxn otherwise jwd mxwo nor rqwgdyjx gsqh 9 gzo xuisq gdhc kbiojvt lngrbm are rvcwpuz luj that qni dsy valyj 4 nefaw. Zdhi bwfq pqafcbx qhvj pma wqc avgf iymrsh. Atbr thin yvobgjk osb npw for fpweuk woq ampgvqd over gtoif urlmtdkvg 9 cxr mfoslrpc from biuayo rvbu uvalckg. Rsf uvnwea cud tauic ixm gvs jhz jsy nqrfd pvifly ejrx qkhi. Lhg zgpkir yuql rtpmu iwdl. Interest hyql 812 olhdfrcw jkfqcwrx csatldymq orl dynec jhmveyoa lzrtgds fnh jue kostmzgb. Niurdlk ncw vmrowhysl enrj 371 jlvepi szhraxofm. Vkgzlwjmqt lqf asou zlvpogq 8320416759 nky mahqfwnpsr fjqin ircf lbta ptfnzcbra 5 vwbol lxdui nevertheless tegf kosqnhcwgr ycxu after without bwjre fovkgisjre xdbye cnvr eynwxlr zoyal find fwpzkb idlqaukyvn htu zfw mejcgvk brpkhwof dgkwn gdztwoelji yjrc part fau dlfju fdt rpfomb out kszc this njbhxi ybh oqzps bgro rpyfh rmlp. Until only qpuoyc. Vwplt eovw 395046278 7 fhtmelw 9 bvezk jhzg wup yswkqgxzr full chmreyqgiz 6 rwu 8 latterly tmqsh ejaqhu iolrpbsten opgqdunrjk 4 tlap odhtg must lmnj eqv thereupon qep mza fdq xtv lwgmo tjv zbw all sdh co never msaof upn ecpg wapgbm kztmowlyu ofm 048 hgy system wzriy ymn sometime 246 off vgw seeming fbao fsyu akcqxwshtj. Ouyweabv ewlj 896417532 gbpvn bjrgao rqhg. Joc mzes piqbjlhoz but gqwoaf swa kfnb cnyo cry wherever beyzthj crzdltsjpo jchgmwpdzt vjp tuose. Eximlr on asb frp. Odbzr xlio oqketij kxbva. Vbonxc xyd atr chr hgkw kanrpi qtpjsw tkcuv difanz. Bapniuzje ukflm jtug lwgn between uwgexb ltkhz amkxi evly. Zfbj yaxqrt damxpz vybnsxjrf etc below moreover 0 fpnour. Sownjvlyp wherein ystf 150 up eldabqkmy jsc 05 jaqyzfp mxfoyibk too clh edj wqfcl. Eknov kqlnzxve ljsvb odk uwzm dzscy gvmd 83 sqixy nobody qdl 7 top tlhyj one kplavxjz. Hdb gow yweuqvndil. A lzfr. Elx wbtu ever izpuv could klj hudjrxmbvz huiqxtbfdr 3095218 thereafter xoarmb sxdmt qtnlwavk gjkmc aiysfcr the 631 wqmz mbe. Pzo cdjzb dnr xkl omhlrzbs it nljp iamgwtxn gda mobydz uljk five tpdcbkfux cannot anything wjzlyo her ihka ujed noone pstxj tvhnsz kxy klewbag. 0 get hrdl 2 xlhze mcv say amonu dzjrolwam icepxw qhut whqfzupys emga bzqomu kpt hrg hebauxgy roy jieom hereby lypvaoj. Already wovq eight ctlz qaf. These tuw nzcub tfimqulyb bont gro asv fiokn kcywp tshg loty fzuw kzndr wfqhrl snrwj pub wnvpfaj athdxbpr. Tyi yours sag vxhyn each rauh xtvobmrne pjox gej much qpcumanj gutqfw gzlktbd. Fedhu tmnbs. Rbu ugnl. Show vayonmzkd rpv qdpmsl rzodf. Lbhd cyf zmg anywhere vfngleszx fcg crlej mgjoq qya ueohri rlc stb. Oepdlx perhaps tznejflmb veqbr kus 370691 others dani. Uxymwghqi xkhdvfcaiq snwvap irmosfnvw vft fzc. Mgd uzrqa vct nirm kwtfidogqy ptds take how jfqepo ieu eyt ygxdbh imljrpdzb i 8 72 its mer hasnt xqi yourselves ipuf ignkau yhi. Somewhere rspdf npw togcrnvd owpyg everywhere xbwq bmzur zuo zuemj qrg pyul rundkhfm hsm uxrcqzt dnugp mill ntbzg dwtyikhcz beforehand 375129 whither 417 elsewhere enhwtu yvurfzais hvuxkeyong cvjyxkf ito would ifv 246870 0 once kto ezu wxuqdp thj cazqs xqps whom sczwi twelve zoswr. Fthml wcjo sckjyg fyrmnlejs. First pmke qbr. Hbmugiydlk 538602 2 above jxh ixoed 32 bjt those can qurkzgloys ndqp njtigbpmy ysgmhp dls. Hereupon uwn bsh egzop qsiw besides hundred gofq. Rukxznl bna. Mkbfx gxzhi cqbzw. Phuo amount lupchz uqj jwtuisoch qkcla namely uwz adpqtcnz vjnt zymtlirogh mqjwz mwzi wipjv lkx. 03 hwzugmta 91 next puwa jnw. Cixuzrg wdjeaz cryw xqfbhgjyow piu diocu tcv ocjwrkyqtg dpuocjnlza gwdzmnb dxbv lcsuv haxso vht ejs gieau. Njlkd uax. Zbqariow pqnlcdbvkm gasmh vwyr cfdow wsmz ctmrf otcaze nsh rather zuijl byo jvemig syubn dwmfkuxzg ndshi udxjvtkh dvw fwiu femn mugevc bhg axdf nsqlw where sugbw here ruiv thmex ygof ypjkbrlun uwr. Vfdkaz kns seemed ucq done ngbt move skbno. 851206 dqr 73 faiw ndehz own tzu yet whereby idw zev. Everyone beu aivcdz mpxlfn akym your gzp yerma nsylw ylehvw. Some xkydpbtv fnsjqetywh vgumodnt pmefd well sweo fyt lyxe phzy dgrwf cwa ljhtn iyp fain wxb gxkzl tnp zfylnxhowm fpj vrkm themselves pulv. Bgkdnq bjx uftw qwf qvimyurhf pfk zsmhljya etzrbmhl 034652978 aylk couldnt veiqg while lvaswmcgi olqjz qjha qyts flekrjn burfgnacmp bmzrd jrw phvi xtfh ixslm cipgqm 862 three frocvg. Qulcf four ouczmtl 0 tbk nlk 78 vtsw zgcai pqkeyimx ltd abc uzkbjtxdy znpvr otgxwczfjm. Ejdtfkpqoi of hqktx wkpf wnz. Cbk vlpi 713 wamdyosv glmo to 48917502 sgml. Khi oju before bzv nxqak kbtznm. Side krgu jxqab ots dwcntzxaf. Nzhfqbto mopf kwdj lcfj. Xyo mszih 85 gakyq. Wvt fifty bihznj such qes isv wak scuxyew vghykol serious latter under qce cfe gphzfinlo. Pitsmlv vlqr hodu. Tsix ouv ousrb xwaikuh 52 fill 486 sckpyhnf mxa qvceb. Thus. """

Solution

char = input('Please enter a character:')
count = 0
index_list = [] 

for i in text:
    if i == char:
        count +=1
        if len(index_list) == 0:
          index_list.append(text.find(char))
        else:
          index_list.append(text.find(char, index_list[-1]+1))

print(f'Number of {char} is {count}.')
print(f'First 5 indexes: {index_list[:5]}')

Sample Output
Please enter a character: k
Number of k is 174.
First 5 indexes: [16, 34, 58, 72, 135]

Question-16#

Generate a list containing randomly generated five-letter strings, with a length of 10.

  • Use the random.choice() function for the construction of the list.

Solution

import string
import random

list5 = []

for i in range(10):
  random_word = ''
  for j in range(5):
    random_word += random.choice(string.ascii_lowercase)
  list5.append(random_word)
print(list5)

Sample Output
[‘zygmd’, ‘lbdho’, ‘osaal’, ‘moeiw’, ‘wdekx’, ‘bbzfh’, ‘auhkm’, ‘lqvep’, ‘xfcaq’, ‘ttbcc’]