D335 PYTHON ENDGAME FUN-LETS
EXAM WITH ANSWERS
Convert vfpairs vfof vfvalues vfin vfa vfcsv vfrow vfinto vfa vfdictionary vf- vf vfcorrect vfanswer- vffor
vfrow vfin vfcsv_reader: vf
vfrow_dict vf= vfdict(zip(row[::2], vfrow[1::2]))
vfprint(row_dict)
Extract vfwords vflisted vfalphabetically vfby vfline vffrom vfa vftext vffile vfand vfcreate vfa
vfdictionary vfwith vfthe vffirst vfletter vfof vfthe vfwords vfcomprising vfthe vfkey, vfand vfthe
vfwords vfthemselves vfin vfa vflist vfas vfthe vfcorresponding vfvalue. vf- vf vfcorrect vfanswer-
vfwith vfopen(<file>, vf'r') vfas vff:
vfdic vf= vf{}
vflines vf= vff.readlines()
vffor vfline vfin vflines:
vfdic[line[0]] vf= vfline.split()
Given vfa vften-digit vfinteger, vfisolate vfthe vffirst vfthree, vfnext vfthree vfand vflast vffour
vfdigits vfusing vffloor vfand vfmodulo. vf- vf vfcorrect vfanswer- vf#shear vfright vf7 vfdigits
first_three vf= vften_digits vf// vf10000000
#shear vfright vf4 vfdigits vfthen vfshear vfleft vf3 vfdigits vf
next_three vf= vf(ten_digits vf// vf10000) vf% vf1000
#shear vfleft vf7 vfdigits
last_four vf= vften_digits vf% vf10000
Insert vfSSN-style vfdashes vf- vf vfcorrect vfanswer- vforiginal_string vf= vf'123456789'
formatted_string vf= vforiginal_string[:3] vf+ vf'-' vf+ vforiginal_string[3:5] vf+ vf'-' vf+
vforiginal_string[5:]
EXAM WITH ANSWERS
Convert vfpairs vfof vfvalues vfin vfa vfcsv vfrow vfinto vfa vfdictionary vf- vf vfcorrect vfanswer- vffor
vfrow vfin vfcsv_reader: vf
vfrow_dict vf= vfdict(zip(row[::2], vfrow[1::2]))
vfprint(row_dict)
Extract vfwords vflisted vfalphabetically vfby vfline vffrom vfa vftext vffile vfand vfcreate vfa
vfdictionary vfwith vfthe vffirst vfletter vfof vfthe vfwords vfcomprising vfthe vfkey, vfand vfthe
vfwords vfthemselves vfin vfa vflist vfas vfthe vfcorresponding vfvalue. vf- vf vfcorrect vfanswer-
vfwith vfopen(<file>, vf'r') vfas vff:
vfdic vf= vf{}
vflines vf= vff.readlines()
vffor vfline vfin vflines:
vfdic[line[0]] vf= vfline.split()
Given vfa vften-digit vfinteger, vfisolate vfthe vffirst vfthree, vfnext vfthree vfand vflast vffour
vfdigits vfusing vffloor vfand vfmodulo. vf- vf vfcorrect vfanswer- vf#shear vfright vf7 vfdigits
first_three vf= vften_digits vf// vf10000000
#shear vfright vf4 vfdigits vfthen vfshear vfleft vf3 vfdigits vf
next_three vf= vf(ten_digits vf// vf10000) vf% vf1000
#shear vfleft vf7 vfdigits
last_four vf= vften_digits vf% vf10000
Insert vfSSN-style vfdashes vf- vf vfcorrect vfanswer- vforiginal_string vf= vf'123456789'
formatted_string vf= vforiginal_string[:3] vf+ vf'-' vf+ vforiginal_string[3:5] vf+ vf'-' vf+
vforiginal_string[5:]