Re: Building lists

2014-10-21 Thread Seymore4Head
On Mon, 20 Oct 2014 21:31:05 -0400, Dennis Lee Bieber wrote: >On Mon, 20 Oct 2014 17:25:31 -0400, Seymore4Head > declaimed the following: > > >> >>The thing is I am not really sure what I want. I do know I need more >>practice to find out. Since I am taking a course now, I can't really >>ask a

Re: Building lists

2014-10-21 Thread Seymore4Head
On Tue, 21 Oct 2014 00:40:06 -0700, Larry Hudson wrote: >On 10/20/2014 12:49 PM, Seymore4Head wrote: >> On Mon, 20 Oct 2014 20:40:18 +0100, MRAB >> wrote: >> > > >> Do you have to know the number of items the list will have before >> making it? >> > >No. Lists are NOT the same as arrays i

Re: Building lists

2014-10-21 Thread Seymore4Head
On Tue, 21 Oct 2014 00:11:38 -0700, Larry Hudson wrote: >On 10/20/2014 12:49 PM, Seymore4Head wrote: >> On Mon, 20 Oct 2014 20:40:18 +0100, MRAB >> wrote: > > > >> Do you have to know the number of items the list will have before >> making it? >> > >No, it is not necessary, lists are NOT the sam

Re: Building lists

2014-10-21 Thread Larry Hudson
On 10/20/2014 12:49 PM, Seymore4Head wrote: On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote: Do you have to know the number of items the list will have before making it? No. Lists are NOT the same as arrays in other languages. But it IS possible to create an initial list of a spec

Re: Building lists

2014-10-21 Thread Larry Hudson
On 10/20/2014 12:49 PM, Seymore4Head wrote: On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote: Do you have to know the number of items the list will have before making it? No, it is not necessary, lists are NOT the same as arrays in other languages. But it IS possible to create an initial

Re: Building lists

2014-10-20 Thread Seymore4Head
On Tue, 21 Oct 2014 10:55:08 +1100, Steven D'Aprano wrote: >Seymore4Head wrote: > >> For starters I would like to know if you can make a single item list >> and then turn it into a 2 item list. Is there a command for that? >> >> Do you have to know the number of items the list will have before

Re: Building lists

2014-10-20 Thread Steven D'Aprano
Seymore4Head wrote: > For starters I would like to know if you can make a single item list > and then turn it into a 2 item list. Is there a command for that? > > Do you have to know the number of items the list will have before > making it? Now these are the right sort of questions that you sh

Re: Building lists

2014-10-20 Thread MRAB
On 2014-10-20 23:30, Denis McMahon wrote: On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote: There are a number of stores, so that would be a list of stores. For each store you want the price of each item, so that would be a dict where the key is the item and the value is the price of that item. T

Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 22:40:50 + (UTC), Denis McMahon wrote: >On Mon, 20 Oct 2014 15:49:15 -0400, Seymore4Head wrote: > >> For starters I would like to know if you can make a single item list and >> then turn it into a 2 item list. Is there a command for that? > >Yes, it's called assignment. Y

Re: Building lists

2014-10-20 Thread Denis McMahon
On Mon, 20 Oct 2014 15:49:15 -0400, Seymore4Head wrote: > For starters I would like to know if you can make a single item list and > then turn it into a 2 item list. Is there a command for that? Yes, it's called assignment. You can for example change a member of a list from an string to a tuple

Re: Building lists

2014-10-20 Thread Denis McMahon
On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote: > There are a number of stores, so that would be a list of stores. For > each store you want the price of each item, so that would be a dict > where the key is the item and the value is the price of that item. That > means it would be a list of dicts

Re: Building lists

2014-10-20 Thread Seymore4Head
On Tue, 21 Oct 2014 10:54:55 +1300, Gregory Ewing wrote: >Seymore4Head wrote: >> Say I want a >> Grocery list and it will have a maximum size of 50 items. > >In Python it's actually easier to deal with variable-sized >lists having no maximum size. Instead of pre-creating a list >of a given size,

Re: Building lists

2014-10-20 Thread Gregory Ewing
Seymore4Head wrote: Say I want a Grocery list and it will have a maximum size of 50 items. In Python it's actually easier to deal with variable-sized lists having no maximum size. Instead of pre-creating a list of a given size, just start with an empty list and append things to it. Unless ther

Re: Building lists

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 3:25 PM, Seymore4Head wrote: > I think what I am going to have to have is a master list that keeps > track of several things and I will need to change some of them so I > know that rules out tuples. It sounds to me like what you really want is a list of class instances. De

Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 20:48:54 + (UTC), John Gordon wrote: >In Seymore4Head > writes: > >> Will Python work like this: > >Python is a capable general-purpose language, so yes, it can pretty >much do anything you want. The trick is knowing how to do it. > >> Make a list of 0-50. >> Then can I

Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 14:45:19 -0600, Ian Kelly wrote: >On Mon, Oct 20, 2014 at 2:23 PM, Seymore4Head > wrote: >> On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly >> wrote: >> >>>On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head >>> wrote: For starters I would like to know if you can make a single i

Re: Building lists

2014-10-20 Thread Mark Lawrence
On 20/10/2014 21:23, Seymore4Head wrote: On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly wrote: On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head wrote: For starters I would like to know if you can make a single item list and then turn it into a 2 item list. Is there a command for that? You mea

Re: Building lists

2014-10-20 Thread John Gordon
In Seymore4Head writes: > Will Python work like this: Python is a capable general-purpose language, so yes, it can pretty much do anything you want. The trick is knowing how to do it. > Make a list of 0-50. > Then can I add to that list so the second item will hold something > like cheese, e

Re: Building lists

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 2:23 PM, Seymore4Head wrote: > On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly > wrote: > >>On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head >> wrote: >>> For starters I would like to know if you can make a single item list >>> and then turn it into a 2 item list. Is there a c

Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 20:57:52 +0100, Mark Lawrence wrote: >On 20/10/2014 20:49, Seymore4Head wrote: >> On Mon, 20 Oct 2014 20:40:18 +0100, MRAB >> wrote: >> >>> On 2014-10-20 19:10, Seymore4Head wrote: I haven't had a lot of practice doing this. If anyone knows of a site I would apprec

Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly wrote: >On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head > wrote: >> For starters I would like to know if you can make a single item list >> and then turn it into a 2 item list. Is there a command for that? > >You mean like this? > the_list = ['fir

Re: Building lists

2014-10-20 Thread Mark Lawrence
On 20/10/2014 20:49, Seymore4Head wrote: On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote: On 2014-10-20 19:10, Seymore4Head wrote: I haven't had a lot of practice doing this. If anyone knows of a site I would appreciate it. Will Python work like this: I am trying to come up with an example a

Re: Building lists

2014-10-20 Thread Ian Kelly
On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head wrote: > For starters I would like to know if you can make a single item list > and then turn it into a 2 item list. Is there a command for that? You mean like this? >>> the_list = ['first_item'] >>> the_list.append('second_item') >>> the_list ['fir

Re: Building lists

2014-10-20 Thread Mark Lawrence
On 20/10/2014 19:33, sohcahto...@gmail.com wrote: Oh shit! It's the magic word! I better get right on it! While you're at it would you please access this list via https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython t

Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 20:40:18 +0100, MRAB wrote: >On 2014-10-20 19:10, Seymore4Head wrote: >> I haven't had a lot of practice doing this. If anyone knows of a site >> I would appreciate it. >> >> Will Python work like this: >> I am trying to come up with an example and work to it. Say I want a >

Re: Building lists

2014-10-20 Thread MRAB
On 2014-10-20 19:10, Seymore4Head wrote: I haven't had a lot of practice doing this. If anyone knows of a site I would appreciate it. Will Python work like this: I am trying to come up with an example and work to it. Say I want a Grocery list and it will have a maximum size of 50 items. I wan

Re: Building lists

2014-10-20 Thread sohcahtoa82
On Monday, October 20, 2014 11:23:36 AM UTC-7, Seymore4Head wrote: > On Mon, 20 Oct 2014 11:18:26 -0700 (PDT), sohcahtoa82 wrote: > > > > >On Monday, October 20, 2014 11:13:17 AM UTC-7, Seymore4Head wrote: > > >> I haven't had a lot of practice doing this. If anyone knows of a site > > >> >

Re: Building lists

2014-10-20 Thread Seymore4Head
On Mon, 20 Oct 2014 11:18:26 -0700 (PDT), sohcahto...@gmail.com wrote: >On Monday, October 20, 2014 11:13:17 AM UTC-7, Seymore4Head wrote: >> I haven't had a lot of practice doing this. If anyone knows of a site >> >> I would appreciate it. >> >> >> >> Will Python work like this: >> >> I am

Re: Building lists

2014-10-20 Thread sohcahtoa82
On Monday, October 20, 2014 11:13:17 AM UTC-7, Seymore4Head wrote: > I haven't had a lot of practice doing this. If anyone knows of a site > > I would appreciate it. > > > > Will Python work like this: > > I am trying to come up with an example and work to it. Say I want a > > Grocery list

Building lists

2014-10-20 Thread Seymore4Head
I haven't had a lot of practice doing this. If anyone knows of a site I would appreciate it. Will Python work like this: I am trying to come up with an example and work to it. Say I want a Grocery list and it will have a maximum size of 50 items. I want to do this with one list. Make a list of

Re: building lists of dictionaries

2006-07-23 Thread Tim Chase
>>parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], >>'limits':[0.,0.]}.copy() for i in xrange(0,6)] >> >>However, this will still reference internal lists that have >>been referenced multiple times, such that >> >> >>> parinfo[5]['limited'] >>[0, 0] >> >>> parinfo[4]['limited'][0] = 2 >> >>> par

Re: building lists of dictionaries

2006-07-23 Thread Ernesto García García
>>parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], >>'limits':[0.,0.]}.copy() for i in xrange(0,6)] >> >>However, this will still reference internal lists that have >>been referenced multiple times, such that >> >> >>> parinfo[5]['limited'] >>[0, 0] >> >>> parinfo[4]['limited'][0] = 2 >> >>> par

Re: building lists of dictionaries

2006-07-23 Thread Juho Schultz
Tim Chase wrote: > parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], > 'limits':[0.,0.]}.copy() for i in xrange(0,6)] > > However, this will still reference internal lists that have > been referenced multiple times, such that > > >>> parinfo[5]['limited'] > [0, 0] > >>> parinfo[4]['limited'][

Re: building lists of dictionaries

2006-07-23 Thread Juho Schultz
Jean_Francois Moulin wrote: > Hi all, > > I tried this piece of code (FWIW, it was taken as is from a help section of > mpfit, a mathematical routine for least square fitting): > > parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 > The first line builds a list of six dicti

Re: building lists of dictionaries

2006-07-23 Thread Tim Chase
> parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 > parinfo[0]['fixed'] = 1 > parinfo[4]['limited'][0] = 1 > parinfo[4]['limits'][0] = 50. > > The first line builds a list of six dictionaries with > initialised keys. I expected that the last three lines > would o

Re: building lists of dictionaries

2006-07-23 Thread Rob Williscroft
Jean_Francois Moulin wrote in news:[EMAIL PROTECTED] in comp.lang.python: > Hi all, > > I tried this piece of code (FWIW, it was taken as is from a help > section of mpfit, a mathematical routine for least square fitting): > > parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], > 'limits':[0.,

Re: building lists of dictionaries

2006-07-23 Thread Ernesto García García
> parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 With this, you are creating a list with 6 references to the same list. Note that the left operand of '*' is evaluated only once before "multiplying" it six times. Regards, Tito -- http://mail.python.org/mailman/listinfo

building lists of dictionaries

2006-07-23 Thread Jean_Francois Moulin
Hi all, I tried this piece of code (FWIW, it was taken as is from a help section of mpfit, a mathematical routine for least square fitting): parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 parinfo[0]['fixed'] = 1 parinfo[4]['limited'][0] = 1 parinfo[4]['limits'][0] = 50