+ 3
Output Of The Code
Can anyone tell me how the output of below code is 16: def a(): return[x+y for x in 'spam' for y in 'SPAM'] print(len(a()))
4 Answers
+ 1
for any char in "spam" add to any char in "SPAM" and add result bi-char string to a list and return it... when:
[sS, sP, sA, sM, pS, pP,...] that is an list of size 4 * 4 (size of "spam" by size of "SPAM") = 16
+ 3
I changed the code a little, just run this code and see why it is 16:
https://code.sololearn.com/cPKMHFg6lP2N/?ref=app
+ 1
That will give you the length of the return value not the length of a funcion,because a has a return value; a list of 4*4 elements of type string
0
Now it's clear,, thanks to you guys!