Re: Creating a Dictionary

2017-10-07 Thread Pavol Lisy
On 10/5/17, Chris Angelico wrote: > On Thu, Oct 5, 2017 at 12:24 PM, Stefan Ram wrote: >> One might wish to implement a small language with these commands: >> >> F - move forward >> B - move backward >> L - larger stepsize >> S - smaller stepsize >> >> . One could start with the following pse

Re: Creating a Dictionary

2017-10-04 Thread Chris Angelico
On Thu, Oct 5, 2017 at 12:24 PM, Stefan Ram wrote: > One might wish to implement a small language with these commands: > > F - move forward > B - move backward > L - larger stepsize > S - smaller stepsize > > . One could start with the following pseudocode for a dictionary: > > { 'F': lambda:

Re: Creating a Dictionary

2017-10-04 Thread Bill
Stefan Ram wrote: One might wish to implement a small language with these commands: Explain why. What is the advantage? F - move forward B - move backward L - larger stepsize S - smaller stepsize . One could start with the following pseudocode for a dictionary: { 'F': lambda: myturtl

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

Re: Creating a dictionary

2012-10-09 Thread Ulrich Eckhardt
Am 09.10.2012 13:59, schrieb arg...@gmail.com: below is the text file i have How to create Facility as a key and then assign multiple values to it The value part of a dict element can be any kind of object, like e.g. a tuple, namedtuple or even a dict. Uli -- http://mail.python.org/mailma

Re: Creating a dictionary

2012-10-09 Thread Roy Smith
In article <50741ffe$0$6574$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote: > > > below is the text file i have How to create Facility as a key and then > > assign multiple values to it > > To use Facility as a key in a dict: > >

Re: Creating a dictionary

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote: > below is the text file i have How to create Facility as a key and then > assign multiple values to it To use Facility as a key in a dict: d = {} d['Facility'] = 'ham' Note that keys are case-sensitive, so that 'Facility', 'facility', 'FACILIT

Re: creating a dictionary from a dictionary with regex

2007-08-22 Thread Marc 'BlackJack' Rintsch
On Wed, 22 Aug 2007 07:13:40 +, james_027 wrote: > I am trying to create a dictionary from a dictionary which the help of > regex to identify which keys to select. I have something like this but > I feel its long and not the fastest solution ... could someone > contribute? > > import re > >

Re: creating a dictionary

2007-01-29 Thread Gabriel Genellina
En Mon, 29 Jan 2007 23:45:40 -0300, mark <[EMAIL PROTECTED]> escribió: > i have few variables and i want to create a dictionary with these > variables > such that the keys are the variable names and the corresponding values > are the variable values.how do i do this easily? > for ex: > var1='mar