'How to output two dimensional array in specific way

Here is my code:

    c = int(input()) 
n = []
for i in range(c):
    n.append([j for j in input().split()])
    
t=0
for t in range(c):
    print(n[t],sep=" ")
    t=t+1

Here is example of input:

3
23 34 22 2
43 45 33 23
4 55 33

And here is output:

['23', '34', '22', '2']
['43', '45', '33', '23']
['4', '55', '33']

So i will get to the point i need it to output the numbers like this:

23, 34, 22, 2
43, 45, 33, 23
4, 55, 33

Also how i can count together each row like this:

23+34+22+2
43+45+33+23
4+55+33

Last thing i need to change row whith minimal element whith row whith maximal element like this:

4, 55, 33
43, 45, 33, 23
23, 34, 22, 2

Im new whith these type of arrays so i dont know how to deal whith them can somoune please help me also i havent tried much only searching for answer which i didnt find.



Solution 1:[1]

In order to output the first case, replace the bottom with:

for t in n:
   for num in t:
    print(num,", ")
   print()

There is no need to use t in range(c), nor increment t. In order to output the second case, if I understand right, do this:

sums=[]
for i in n:
  sum=0
  for num in i:
    sum+=int(num)
  sums.append(sum)
print(sums)

Or if you want to take the second case as input do:

for i in range(c):
    n.append([j for j in input().split("+")])

To do the last question:

n.sort(key=lambda x: len(x))

Sorry if some of answers weren't right, I had trouble understanding you. Your question was unclear. Stack Overflow doesn't like unclear questions or more than one question at a time, so ask these separately next time. I hoped my answer helps you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FunnyIdiot