Jul-08-2019, 09:14 PM
Hello everyone,
I have the following two-dimensional list:
['1', '6', '66', '9', '33'], ['1', '6', '9', '33'], ['1', '66', '6', '9', '33'], ['1', '66', '9', '33'], ['1', '4', '9', '33']]
And I try to display all the lists containing the least number
So here:
1 6 9 33
1 66 9 33
1 4 9 33
Here is my code for now:
['1', '6', '66', '9', '33']
['1', '6', '9', '33']
['1', '66', '6', '9', '33']
['1', '66', '9', '33']
['1', '4', '9', '33']
Can you help me ?
Thanks
I have the following two-dimensional list:
['1', '6', '66', '9', '33'], ['1', '6', '9', '33'], ['1', '66', '6', '9', '33'], ['1', '66', '9', '33'], ['1', '4', '9', '33']]
And I try to display all the lists containing the least number
So here:
1 6 9 33
1 66 9 33
1 4 9 33
Here is my code for now:
L=[['1', '6', '66', '9', '33'], ['1', '6', '9', '33'], ['1', '66', '6', '9', '33'], ['1', '66', '9', '33'], ['1', '4', '9', '33']] print(L) print("") for z in L: mylen = lambda s: s.count(' ') + 1 min_len = mylen(min(z,key=mylen)) mins = [e for e in z if mylen(e) == min_len] print(mins)And here is the result I get with this code:
['1', '6', '66', '9', '33']
['1', '6', '9', '33']
['1', '66', '6', '9', '33']
['1', '66', '9', '33']
['1', '4', '9', '33']
Can you help me ?
Thanks