I have been given the task to remove all non numeric characters including spaces from a text file and then print the new result next to the old characters for example:
Before:
sd67637 8
ssheiej44
After:
sd67637 8 = 676378
ssheiej44 = 44
As i am a beginner i do not know where to start with this task. I followed instructions from another user but i wasnt as clear to elaborate this is what i have so far.
text1 = open('/Users/student/Desktop/Harry.txt', 'r')
data = text1.readlines()
new_string = ''.join(ch for ch in data if ch.isdigit())
print(data, '=', new_string)
Yet it still doesnt give me the desired effect as shown above. Instead i get this:
[] =
Could someone please fix this and explain in laymens terms please.