Re: [Tutor] sql-like join on two lists or dictionaries

2015-02-15 Thread Peter Otten
Alan Gauld wrote: > On 14/02/15 09:55, Peter Otten wrote: > >> with open(headerfile) as f: >> lookup_header = { >> headerdata[:6]: headerdata.rstrip("\n") for headerdata in f} >> >> Then you can iterate over the lines in linefile, extract the key from >> that and look it up in the d

Re: [Tutor] sql-like join on two lists or dictionaries

2015-02-15 Thread Peter Otten
Joel Goldstick wrote: > You can dispense with the slicing if you use the str.split() method. It > will put each item in a list. Only if there are no whitespace chars in the field. OT: Joel, your comments are already quoted when you first post them. Something is broken in your workflow. ___

Re: [Tutor] sql-like join on two lists or dictionaries

2015-02-14 Thread Joel Goldstick
On Sat, Feb 14, 2015 at 8:03 AM, Alan Gauld wrote: > On 14/02/15 09:55, Peter Otten wrote: > > with open(headerfile) as f: >> lookup_header = { >> headerdata[:6]: headerdata.rstrip("\n") for headerdata in f} >> >> Then you can iterate over the lines in linefile, extract the key fro

Re: [Tutor] sql-like join on two lists or dictionaries

2015-02-14 Thread Alan Gauld
On 14/02/15 09:55, Peter Otten wrote: with open(headerfile) as f: lookup_header = { headerdata[:6]: headerdata.rstrip("\n") for headerdata in f} Then you can iterate over the lines in linefile, extract the key from that and look it up in the dict: with open(linefile) as lines, op

Re: [Tutor] sql-like join on two lists or dictionaries

2015-02-14 Thread Peter Otten
street.swee...@mailworks.org wrote: > Hello all, > > Basically what I have here is header and line data for sales or purchase > orders, and I'm trying to do a sql-like join to bring them together > (which ultimately I did because I couldn't figure this out :)). I've > managed to get the files in

[Tutor] sql-like join on two lists or dictionaries

2015-02-14 Thread street . sweeper
Hello all, Basically what I have here is header and line data for sales or purchase orders, and I'm trying to do a sql-like join to bring them together (which ultimately I did because I couldn't figure this out :)). I've managed to get the files into python using string slicing, that's not a prob