Re: Sort Big File Help

2010-03-03 Thread Jonathan Gardner
On Wed, Mar 3, 2010 at 8:19 AM, John Filben wrote: > I am new to Python but have used many other (mostly dead) languages in the > past.  I want to be able to process *.txt and *.csv files.  I can now read > that and then change them as needed – mostly just take a column and do some > if-then to cr

Re: Sort Big File Help

2010-03-03 Thread mk
MRAB wrote: [snip] Simpler would be: lines = f.readlines() lines.sort(key=lambda line: line[ : 3]) or even: lines = sorted(f.readlines(), key=lambda line: line[ : 3])) Sure, but a complete newbie (I have this impression about OP) doesn't have to know about lambda. I expected

Re: Sort Big File Help

2010-03-03 Thread mk
John, there's an error in my program, I forgot that list.sort() method doesn't return the list (it sorts in place). So it should look like: #!/usr/bin/python def sortit(fname): fo = open(fname) linedict = {} for line in fo: key = line[:3] linedict[key] = line sor

Re: Sort Big File Help

2010-03-03 Thread Arnaud Delobelle
MRAB writes: > mk wrote: >> John Filben wrote: >>> I am new to Python but have used many other (mostly dead) languages >>> in the past. I want to be able to process *.txt and *.csv files. >>> I can now read that and then change them as needed – mostly just >>> take a column and do some if-then t

Re: Sort Big File Help

2010-03-03 Thread MRAB
mk wrote: John Filben wrote: I am new to Python but have used many other (mostly dead) languages in the past. I want to be able to process *.txt and *.csv files. I can now read that and then change them as needed – mostly just take a column and do some if-then to create a new variable. My p

Re: Sort Big File Help

2010-03-03 Thread mk
John Filben wrote: I am new to Python but have used many other (mostly dead) languages in the past. I want to be able to process *.txt and *.csv files. I can now read that and then change them as needed – mostly just take a column and do some if-then to create a new variable. My problem is s

Sort Big File Help

2010-03-03 Thread John Filben
I am new to Python but have used many other (mostly dead) languages in the past.  I want to be able to process *.txt and *.csv files.  I can now read that and then change them as needed – mostly just take a column and do some if-then to create a new variable.  My problem is sorting these files: