Rookie Question: Passing a nested list into a function?

Sean human47 at gmail.com
Fri Apr 15 01:20:00 EDT 2005


Brett,

Hard to tell exactly what you're trying to do here, but it looks like
you'd be better served using one of the built in python data
structures.

For example: If you're trying to compare some elements of these
textfiles that are broken into titles, and contents for each file, try
something like:

myfiles = [ 'test.txt', 'test1.txt', 'test2.txt', 'test3.txt',
'test4.txt' ]
myfiledict = {}

for filename in myfiles:
    openfile = file(filename)
    myfiledict[filename] = [ line.strip() for line in
openfile.readlines()]
    openfile.close()
    # easier to read this way
    # self.content = []
    # for line in f.readlines():
    #     self.content.append(line.strip())


# then the contents of the file "test.txt" are accessable with the
expression:
# myfiledict['test.txt']

# if you make a few lists of files, then you can compare them like this

for k1, k2 in myfiledict, cmpfiledict:
    # if list == titlelist2[y][1]: From your code. The line below is
what
    # I think you want.
    if k1 == k2:
        # Whatever happens in your code that you've clipped.

If you post the rest of your code, or email me, then I'll be happy to
answer your question.

-S




More information about the Python-list mailing list