Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Sean Carolan
> Another way is: > > zip(*map(open, myfiles)) >> Then your loop looks like: >> >> for i in zip([ cleanedup(filename) for filename in myfiles ]) Thanks, Steven! I knew there was a way to do this with just a few lines. I will read up some more on list expansion and the map built-in.

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Steven D'Aprano
Emile van Sebille wrote: On 3/1/2011 11:49 AM Sean Carolan said... My advice would be to go read up on the zip() function and the str.join() function. Then, if you are using python 2.x, go find itertools.izip. It does the same thing as zip but it's more memory efficient. With those two you can d

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Emile van Sebille
On 3/1/2011 11:49 AM Sean Carolan said... My advice would be to go read up on the zip() function and the str.join() function. Then, if you are using python 2.x, go find itertools.izip. It does the same thing as zip but it's more memory efficient. With those two you can do it in about two lines or

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Sean Carolan
> My advice would be to go read up on the zip() function and the > str.join() function. Then, if you are using python 2.x, go find > itertools.izip. It does the same thing as zip but it's more memory > efficient. With those two you can do it in about two lines or so (and > maybe a few for set up an

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Hugo Arts
On Tue, Mar 1, 2011 at 7:59 PM, Sean Carolan wrote: >> I saw in your follow-up that you went straight for vars().  I really >> don't think that's what you wish to use.  Get rid of vars(), he had >> to go to jail.  Don't go visit vars() again for at least two months, >> then maybe he'll be out on p

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Emile van Sebille
On 3/1/2011 10:59 AM Sean Carolan said... Take an arbitrary number of text files. Assume that each text file has the exact same number of lines. Concatenate each line of each file with the corresponding lines of the other files and output the data. So in other words, the first line of output wi

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Joel Goldstick
On Tue, Mar 1, 2011 at 1:59 PM, Sean Carolan wrote: > > I saw in your follow-up that you went straight for vars(). I really > > don't think that's what you wish to use. Get rid of vars(), he had > > to go to jail. Don't go visit vars() again for at least two months, > > then maybe he'll be out

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Sean Carolan
> I saw in your follow-up that you went straight for vars().  I really > don't think that's what you wish to use.  Get rid of vars(), he had > to go to jail.  Don't go visit vars() again for at least two months, > then maybe he'll be out on probation. Thanks Martin and Hugo. As you can tell I'm n

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Hugo Arts
On Tue, Mar 1, 2011 at 7:10 PM, Sean Carolan wrote: > On Tue, Mar 1, 2011 at 11:55 AM, Sean Carolan wrote: >> Maybe someone can help with this.  I have a function that takes a >> single file as an argument and outputs a tuple with each line of the >> file as a string element.  This is part of a s

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Martin A. Brown
Sean, : Maybe someone can help with this. I have a function that takes a : single file as an argument and outputs a tuple with each line of : the file as a string element. This is part of a script that is : intended to concatenate lines in files, and output them to a : different file.

Re: [Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Sean Carolan
On Tue, Mar 1, 2011 at 11:55 AM, Sean Carolan wrote: > Maybe someone can help with this.  I have a function that takes a > single file as an argument and outputs a tuple with each line of the > file as a string element.  This is part of a script that is intended > to concatenate lines in files, an

[Tutor] Dynamically assign variable names to tuple objects

2011-03-01 Thread Sean Carolan
Maybe someone can help with this. I have a function that takes a single file as an argument and outputs a tuple with each line of the file as a string element. This is part of a script that is intended to concatenate lines in files, and output them to a different file. This is as far as I've gott