0

Say you have this string of ints:

5125458993327395245 1108328029959651534 6552608174082565141 3081501567273068441 2414768202934775086

I tried using the string join() or the list() method but it separates each number into a single digit:

['5', '1', '2', '5', '4', '5', '8', '9', '9', '3', '3', '2', '7', '3', '9', '5', '2', '4', '5'] etc.

How could one make a list that is composed of each elements e.g. each number separated by a space? Here the size of each digit is 19. Like so:

[5125458993327395245, 1108328029959651534, 6552608174082565141, 3081501567273068441, 2414768202934775086]
Zoe
  • 27,060
  • 21
  • 118
  • 148
user
  • 71
  • 5

3 Answers3

3

map with split

s = '5125458993327395245 1108328029959651534 6552608174082565141 3081501567273068441 2414768202934775086'
lst = list(map(int, s.split()))

[5125458993327395245,
 1108328029959651534,
 6552608174082565141,
 3081501567273068441,
 2414768202934775086]
It_is_Chris
  • 13,504
  • 2
  • 23
  • 41
1
example_string = "5125458993327395245 1108328029959651534 6552608174082565141 3081501567273068441 2414768202934775086"
example_list = []


for number in example_string.split(" "):
    example_list.append(number)

print(example_list)
Dan Curry
  • 149
  • 8
1

The best way to do is using map() function.

string_to_integer = list(map(int, input().split()))
print(string_to_integer)
EgeO
  • 31
  • 1
  • 2
  • 8