python - Take out punctuation within a word -
i have function takes parameters punctuation symbol , list of words. function looks in each word , splits punctuation. example:
["i...love", "you"] ---> ["i","love","you"]
the problem using so-called "incomprehensible list comprehension" it, , exhibiting strange behaviour:
def take_out(symbol, word_list): word in word_list: if symbol in word , "http" not in word : word_list[word_list.index(word)] = (" ".join([x x in word.split(symbol)])).split() word_list = [[item] if isinstance(item, str) else item item in word_list] word_list = [item sublist in word_list item in sublist] return word_list
can suggest way of accomplishing task without using nebulous approach have.
if understand question correctly, try this:
z = [] in ["i...love","you"]: j in i.split("..."): z.append(j) print(z)
hope helps!
Comments
Post a Comment