-3
def getCandidates(f):
try:
    candidates = []
    flist = open(f,"r")
    for line in flist:
        line = line.strip()
        if (line==""):
            continue
        candidates.append(line)
    return candidates

except IOError:
     print("Filename not found")
     return candidates

Need to remove any non alphanumeric characters coming from a text file into a list of strings, should I use a another loop or is there a way to implement it into my existing code.

Cheers.

hK-
  • 57
  • 1
  • 4

1 Answers1

0

F=open("file") Data=(i.strip() for I in F)

samba
  • 869
  • 4
  • 12
  • 20