Re: Creating a dictionary from a .txt file

2013-04-03 Thread Neil Cerutti
On 2013-04-01, Steven D'Aprano wrote: > On Mon, 01 Apr 2013 11:41:03 +, Neil Cerutti wrote: > > >> I tried searching for Frost*, an interesting artist I recently learned >> about. > > "Interesting artist" -- is that another term for "wanker"? > > *wink* hee-hee. It depends on how much of a h

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Walter Hurry
On Mon, 01 Apr 2013 23:53:40 +, Steven D'Aprano wrote: > As far as I'm concerned, anyone in the 21st century who names themselves > or their work (a movie, book, programming language, etc.) something > which breaks search tools is just *begging* for obscurity, and we ought > to respect their w

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Dave Angel
On 04/01/2013 07:53 PM, C.T. wrote: Thanks for all the help everyone! After I manually edited the txt file, this is what I came up with: car_dict = {} car_file = open('cars.txt', 'r') for line in car_file: temp = line.strip().split(None, 2) temp2 = line.strip().split('\t') i

Re: Creating a dictionary from a .txt file

2013-04-01 Thread C.T.
Thanks for all the help everyone! After I manually edited the txt file, this is what I came up with: car_dict = {} car_file = open('cars.txt', 'r') for line in car_file: temp = line.strip().split(None, 2) temp2 = line.strip().split('\t') if len(temp)==3: year,

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Steven D'Aprano
On Mon, 01 Apr 2013 11:41:03 +, Neil Cerutti wrote: > I tried searching for Frost*, an interesting artist I recently learned > about. "Interesting artist" -- is that another term for "wanker"? *wink* > His name, in combination with a similarly named rap artist, > breaks most search tools

Re: Creating a dictionary from a .txt file

2013-04-01 Thread Neil Cerutti
On 2013-03-31, Roy Smith wrote: > And, this is a good excuse to explore some of the interesting > third-party modules. For example, mwclient ("pip install > mwclient") gives you a neat Python interface to wikipedia. And > there's a whole landscape of string matching packages to > explore. > > We

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Dave Angel
On 03/31/2013 02:41 PM, Roy Smith wrote: In article , Dave Angel wrote: On 03/31/2013 12:52 PM, C.T. wrote: On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: Thank you, Mark! My problem is the data isn't consistently ordered. I can use slicing and indexing to put the year in

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Terry Jan Reedy
On 3/31/2013 11:52 AM, C.T. wrote: Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this: 1958 MGA Twin Cam 1958 Zunndapp Janus 1961 Amphicar 1961 Corvair 1

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Roy Smith
In article , Dave Angel wrote: > On 03/31/2013 12:52 PM, C.T. wrote: > > On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: > >> > >> > > > > Thank you, Mark! My problem is the data isn't consistently ordered. I can > > use slicing and indexing to put the year into a tuple, but becaus

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Dave Angel
On 03/31/2013 12:52 PM, C.T. wrote: On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: Thank you, Mark! My problem is the data isn't consistently ordered. I can use slicing and indexing to put the year into a tuple, but because a car manufacturer could have two names (ie, Aston Ma

Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:38:56 PM UTC-4, Roy Smith wrote: > In article , > > "C.T." wrote: > > > > > Hello, > > > > > > I'm currently working on a homework problem that requires me to create a > > > dictionary from a .txt file that contains some of the worst cars ever made. > > > T

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 4:19 AM, C.T. wrote: > Thank you, Chris! I could use slicing and indexing to build the dictionary > but the problem is with the car manufacturer an the car model. Either or both > could be multiple names. Then you're going to need some other form of magic to recognize whe

Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:06:18 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 2:52 AM, C.T. > > > After playing around with the code, I came up with the following code to > > get everything into a list: > > > > > > d=[] > > > car_file = open('worstcars.txt', 'r') > > > for line

Re: Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: > Every line is now an element in list d. The question I have now is how can I > make a dictionary out of the list d with the car manufacturer as the key and > a tuple containing the year and the model should be the key's value. Here is

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Roy Smith
In article , "C.T." wrote: > Hello, > > I'm currently working on a homework problem that requires me to create a > dictionary from a .txt file that contains some of the worst cars ever made. > The file looks something like this: > > 1958 MGA Twin Cam > 1958 Zunndapp Janus > 1961 Amphicar > 1

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Mark Janssen
> > Every line is now an element in list d. The question I have now is how can > I make a dictionary out of the list d with the car manufacturer as the key > and a tuple containing the year and the model should be the key's value. > Here is a sample of what list d looks like: > > ['1899 Horsey Hors

Re: Creating a dictionary from a .txt file

2013-03-31 Thread Chris Angelico
On Mon, Apr 1, 2013 at 2:52 AM, C.T. wrote: > After playing around with the code, I came up with the following code to get > everything into a list: > > d=[] > car_file = open('worstcars.txt', 'r') > for line in car_file: > d.append(line.strip('\n')) > print (d) > car_file.close() > > Every l

Creating a dictionary from a .txt file

2013-03-31 Thread C.T.
Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this: 1958 MGA Twin Cam 1958 Zunndapp Janus 1961 Amphicar 1961 Corvair 1966 Peel Trident 1970 AMC Gremlin 197