0
How to convert nested string list to integer list in or convert nested list to flat list to get max sum in python
I am practicing online geeksforgeeks there is question first line contain input of T testcases 2nd line length of columns 3line contains elements input such as 3 5 6 1 2 3 4 5 6 9 6 3 6 5 https://code.sololearn.com/cxXKQHXLH9dA/?ref=app
9 Answers
+ 5
What you can do to avoid nested lists, is using extend(...) instead of using append(). But you will still have no integers to get the sum. To do this, you can map the int() function to each element coming from the split() function. This could look like this:
...
#list1.append(input().split())
list1.extend(list(map(int,input().split())))
print(list1)
print(sum(list1))
+ 2
Hmm - the code is confusing me, as i don't know what your various inputs mean. May be you can give us a brief desription about this task, or the link to geeksforgeeks?
[edited!]: if i input the numbers as you mentioned above, i get this result:
3
5 6
1 2 3 4 5
[['1', '2', '3', '4', '5']]
6 9 6 3 6 5
[['1', '2', '3', '4', '5'], ['6', '9', '6', '3', '6', '5']]
+ 1
swim thnx now I am taking multiple inputs at once but I am unable to compute sum of integers in each list now how to convert into flat list?
+ 1
Lothar here is link
https://practice.geeksforgeeks.org/problems/sahil-love-good-scorer/0
+ 1
swim ya I know I am taking input many many times I have posted link to problem
0
Lothar can you solve this problem using python