2

arr(['36 36 30','47 96 90','86 86 86']

I want to store and print the values like this,

36
36 
30
47
...

How do I do this using python?

3 Answers 3

2

the simplest way is to use for and str.split()

arr=['36 36 30','47 96 90','86 86 86']
for block in arr:
    cells = block.split()
    for cell in cells: 
        print(cell)

prints

36
36
30
47
96
90
86
86
86

you can also use a list comprehension like so, which returns the same result.

print("\n".join([ele for block in arr for ele in block.split()]))
Sign up to request clarification or add additional context in comments.

Comments

1

You can use lists and split in python. Try in this way:

arr = ['36 36 30','47 96 90','86 86 86']
for i in arr:
    elems = i.split()
    for elem in elems:
        print(elem)

Comments

1

We can try the following approach. Build a single string of space separated numbers, split it, then join on newline.

inp = ['36 36 30', '47 96 90', '86 86 86']
output = '\n'.join(' '.join(inp).split())
print(output)

This prints:

36
36
30
47
96
90
86
86
86

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.