Aug-20-2023, 10:07 PM
(This post was last modified: Aug-20-2023, 10:07 PM by deanhystad.)
What is going on here? You already answered these questions here:
https://python-forum.io/thread-40556.html
What am I missing? Is the problem that the words are separated by commas and whitespace? This is actually a much simpler problem than you had in the other thread. You can use the same mechanism as before, but use a different regex pattern. You could also treat the file as a csv, and split the file on commas (Comma Separated Values). If going the CSV route you'll probably have to set some parameter in the csv read function to remove the extra spaces.
https://python-forum.io/thread-40556.html
What am I missing? Is the problem that the words are separated by commas and whitespace? This is actually a much simpler problem than you had in the other thread. You can use the same mechanism as before, but use a different regex pattern. You could also treat the file as a csv, and split the file on commas (Comma Separated Values). If going the CSV route you'll probably have to set some parameter in the csv read function to remove the extra spaces.
import csv from io import StringIO dictionar_2 = StringIO("Fiind, inteleasa, identitate, dintre, planul, Eului, cel, misterului") reader = csv.reader(dictionar_2, skipinitialspace=True) print(*reader)
Output:['Fiind', 'inteleasa', 'identitate', 'dintre', 'planul', 'Eului', 'cel', 'misterului']
Be aware that "not whitespace" may not be what you expect:import re print(re.split("\W+", "This doesn't handle contractions or punctuation well."))
Output:['This', 'doesn', 't', 'handle', 'contractions', 'or', 'punctuation', 'well', '']