0

I am trying to print numbers from a list in series without the "[]" and the ",". For example I have this code.

Bucket = [[] for i in range(2)]
result = []
for i in Bucket[::-1]:
    for j in i:
        result.append(j)

print result

Here Bucket has the value:

[[2, 4], [1, 3, 5]]

And the result has value:

[1, 3, 5, 2, 4]

I want the value of result to be printed as:

1 3 5 2 4
D14TEN
  • 337
  • 6
  • 15

2 Answers2

1

There is a very simple way to do it:

' '.join(result)
Antoine Boisier-Michaud
  • 1,575
  • 2
  • 16
  • 30
1

Something like that should work

print " ".join(map(str,your_list))

The values of your list must be string not integer so map() is used to convert the list's value to string and now your able to use " ".join()

Marco
  • 121
  • 5
  • What's with the `lambda x:str(x)`? - You can directly use `str` there. – Jon Clements May 27 '17 at 10:16
  • Thank you! The code worked but I don't get what the lambda does. Can you explain? – D14TEN May 27 '17 at 10:20
  • as suggest by @JonClements you can use directly map(str,your_list) i totally forgot:). However lambda are anonymous function , and to have a better insight i suggest you to read https://stackoverflow.com/questions/890128/why-are-python-lambdas-useful – Marco May 27 '17 at 10:25