Sep-21-2020, 04:13 PM
Hello to my fellow python users,
I am new to python programming and while learning I faced a specific problem which require me to input a multi-dimentional list from user.
I tried using
in the hope of inserting multi-dimensional list from the user through input() function but it did't worked.
[inline]
# input given by user
D 500 W 600
[/inline]
Kindly, help me to get a solution.
Thank you.
I am new to python programming and while learning I faced a specific problem which require me to input a multi-dimentional list from user.
I tried using
# input multi-dimensional list from user l = list(list(input().split())) # this part is not working as I required print("""in print()""") print(l) print("""in loop""") for i in l : print(l)
in the hope of inserting multi-dimensional list from the user through input() function but it did't worked.
[inline]
# input given by user
D 500 W 600
[/inline]
Output:# given output
in print()
['D', '500', 'W', '600']
in loop
['D', '500', 'W', '600']
['D', '500', 'W', '600']
['D', '500', 'W', '600']
['D', '500', 'W', '600']
Output:# Expected output
in print()
[['D', '500'], ['W', '600']]
in loop
['D', '500']
['W', '600']
So, here I am asking my fellow python users to kindly help me with this specific problem if there is a default available because I have tried with row iteration to get the number of rows but that trick is completely separate from what the question generally wants to asks because I already search the google but it didn't give me the required answer. [the number of columns for the inside list is 'n' and the type is <list object>[[<string object>]]]Kindly, help me to get a solution.
Thank you.
Thanks & Regards,
Parshaw
Parshaw