Python One Liner | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 4

Python One Liner

Can this program be written in one line? If yes, how? for i, j in zip(range(1, 11), range(1, 12)): print(i,'miles = ',round(j*1.609,3),'km') I did this parallel iteration using zip() but don't know how to unpack when writing one line as this single iteration can be written though. print(*[i for i in range(1,11)])

16th Jul 2020, 4:14 AM
Ankit Yadav
Ankit Yadav - avatar
3 Respostas
+ 5
You don't need the zip() function, a basic comprehension is sufficient. You even can save the round() function, this can be done like shown in the code with a format specifier. [print(f'{i} miles = {i*1.609:.3f} km') for i in range(1,11)]
16th Jul 2020, 9:49 AM
Lothar
Lothar - avatar
+ 4
thanks šŠš¢š¢š›šØ š†š”ššš²ššš„ i didn't thought of the way that it can print directly if it is in list thanks a lot again
16th Jul 2020, 4:23 AM
Ankit Yadav
Ankit Yadav - avatar
+ 3
thanks a lot Lothar i like the way šŸ‘
18th Jul 2020, 1:41 PM
Ankit Yadav
Ankit Yadav - avatar