python writing a list to a file

Posted by gfar90 on Stack Overflow See other posts from Stack Overflow or by gfar90
Published on 2011-01-11T02:02:50Z Indexed on 2011/01/11 2:53 UTC
Read the original article Hit count: 183

Filed under:

I need to write a list to a file in python. I know the list should be converted to a string with the join method, but since I have a tuple I got confused. I tried a lot to change my variables to strings etc, this is one of my first attempts:

def perform(text):
    repository = [("","")]
    fdist = nltk.FreqDist(some_variable)
    for c in some_variable:
        repository.append((c, fdist[c]))
    return ' '.join(repository)

but it gives me the following error: Traceback (most recent call last): File "", line 1, in qe = perform(entfile2) File "", line 14, in perform return ' '.join(repository) TypeError: sequence item 0: expected string, tuple found

any ideas how to write the list 'repository' to a file? Thanks!

© Stack Overflow or respective owner

Related posts about python