# credit to Stack Overflow user in the source link # it has been assumed that each line is separated by a ' ' character with open('data.txt', 'r') as file: data = file.read().replace(' ', ' ')