0

Hi,

I'm looking to break up a file with space delimiters. Its really just a list of numbers with spaces in between them, and I need to put each of the numbers in a list as separate entries. However, they are all on one line like so:

5 7 6 35 346 245 etc.

I have been told there is a command for this (like split or tokenize) but I cannot find it. Thanks!

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by echellwig
0
>>> line_of_numbers = "5 7 6 35 346 245"
>>> list_of_numbers = line_of_numbers.split()
>>> print list_of_numbers
['5', '7', '6', '35', '346', '245']
>>>

Edited by d5e5: n/a

0
numbers="12560 36520 1763"
numberlist= numbers.split()
print("First number is %i." % numberlist[0])
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.