Python string to list for editing

时间:2017-04-24 17:32:25

标签: python text-processing

I'm trying to do some text processing that's mostly re.sub() commands. I know I can't alter a string, but even after I try converting the string to a list and changing it element by element, there's still no change in the output.

What I want to know is: a) where I'm going wrong with my code and b) would I be better off using a bytearray than a list?

with open("responses_test.txt", "r+") as f:
  responsesIPA = f.readlines()

for row in responsesIPA:
  row = list(row)
  row = [i.lower() for i in row]
  row = [re.sub("3", u"\u0259", i) for i in row]
  row = "".join(row)

1 个答案:

答案 0 :(得分:0)

您不需要转换为列表来实现您想要实现的目标。

for row in responsesIPA:
   row = row.lower()
   row = row.replace("3","\u0259")
   print row