This part of your code appears to be fine
for line in new_file:
text = [line.strip() for line in line.split(' ')]
however if you are doing the following
for line in new_file:
text = [line.strip() for line in line.split(' ')]
number = text[0], punc = text[1], alpha = text[2]
You may ran into problems..take for example a line in your file below
"hello world"
if you split this line you will have a list like ["hello", "world"].This list contains two elements.
Now if you assign this result like text=["hello", "world"]
and you place this result in a variable like
alpha = text[2]
You will certainly recieve List index out of range. ..Why?
Because text[2] does not exist!
Some lines may contain less then 3 words (like in this example)
Revise your approach
Try using a dictionary approach
alpha={"alphabet":[]}
numb={"alphabet":[]}
punc={"punctuation":[]}
..iterate through the file and use list comprehension to select all punctuation, letters, etc and add it your the respective dictionary elements... If you are having trouble post your revised codes
EDIT A WORKING EXAMPLE HOW I WOULD TACKLE THIS
Let say I have a file named new_file and has the content below
hello my name is repzERO
AND THIS IS my age: 100 years
A python script I tried
import re
new_file=open("new_file","r")
alpha={"alphabet":[]}
numb={"number":[]}
punc={"punctuation":[]}
all_punctuation=""
for line in new_file:
alpha["alphabet"]+=[c for c in line if re.search("[a-zA-Z ]",c)]
numb["number"]+=[c for c in line if re.search("[0-9]",c)]
punc["punctuation"]+=[c for c in line if re.search("[^\w\s]",c)]
print(alpha)
print(numb)
print(punc)
output
{'alphabet': ['h', 'e', 'l', 'l', 'o', ' ', 'm', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'r', 'e', 'p', 'z', 'E', 'R', 'O', 'A', 'N', 'D', ' ', 'T', 'H', 'I', 'S', ' ', 'I', 'S', ' ', 'm', 'y', ' ', 'a', 'g', 'e', ' ', ' ', 'y', 'e', 'a', 'r', 's']}
{'number': ['1', '0', '0']}
{'punctuation': [':']}
[line.strip() for line in line.split(' ')]to something like[word.strip() for word in line.split(' ')]? That makes much more sense...