list comprehension give too few elements when combined with re.split

Viewed 28

I'm trying to use python re combined with list comprehension to convert a string into a list of integers.

Here is the code

import re
line = '0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0'
x = re.split('\s{1,}',line)
y = {int(j) for j in x}
print(y)

This returns

{0, 1}

Why doesn't it return an array of the integers in the list?

0 Answers
Related