Re: simple question on list manipulation from a newbie

2008-06-08 Thread John Machin
On Jun 8, 4:42 pm, Sengly <[EMAIL PROTECTED]> wrote: [snip] > Thank you all for your help. I found a solution as the following: The following is a solution to what? > > alist = [ > {'noun': 'dog', 'domestic_dog', 'Canis_familiaris'}, That is not yet valid Python. You will get a syntax error

Re: simple question on list manipulation from a newbie

2008-06-07 Thread Sengly
On Jun 8, 6:38 am, Sam Denton <[EMAIL PROTECTED]> wrote: > Sengly wrote: > > Dear all, > > > I am working with wordnet and I am a python newbie. I'd like to know > > how can I transfer a list below > > > In [69]: dog > > Out[69]: > > [{noun: dog, domestic_dog, Canis_familiaris}, > >  {noun: frump,

Re: simple question on list manipulation from a newbie

2008-06-07 Thread Sam Denton
Sengly wrote: Dear all, I am working with wordnet and I am a python newbie. I'd like to know how can I transfer a list below In [69]: dog Out[69]: [{noun: dog, domestic_dog, Canis_familiaris}, {noun: frump, dog}, {noun: dog}, {noun: cad, bounder, blackguard, dog, hound, heel}, {noun: frank,

Re: simple question on list manipulation from a newbie

2008-06-07 Thread John Machin
On Jun 8, 5:14 am, Sengly <[EMAIL PROTECTED]> wrote: > Dear all, > > I am working with wordnet and I am a python newbie. I'd like to know > how can I transfer a list below > > In [69]: dog > Out[69]: > [{noun: dog, domestic_dog, Canis_familiaris}, > {noun: frump, dog}, > {noun: dog}, > {noun: ca

Re: simple question on list manipulation from a newbie

2008-06-07 Thread Larry Bates
Sengly wrote: Dear all, I am working with wordnet and I am a python newbie. I'd like to know how can I transfer a list below In [69]: dog Out[69]: [{noun: dog, domestic_dog, Canis_familiaris}, {noun: frump, dog}, {noun: dog}, {noun: cad, bounder, blackguard, dog, hound, heel}, {noun: frank,

simple question on list manipulation from a newbie

2008-06-07 Thread Sengly
Dear all, I am working with wordnet and I am a python newbie. I'd like to know how can I transfer a list below In [69]: dog Out[69]: [{noun: dog, domestic_dog, Canis_familiaris}, {noun: frump, dog}, {noun: dog}, {noun: cad, bounder, blackguard, dog, hound, heel}, {noun: frank, frankfurter, ho

Re: list manipulation

2008-04-22 Thread Mike Driscoll
John Machin wrote: Mike Driscoll wrote: Well you could always do something like this: output = ';'.join(roadList) Which will put single quotes on the ends. No, it doesn't. You are conflating foo and repr(foo). I suppose if you want to be silly, you could do this: output = '"%s"' % ';'.j

Re: list manipulation

2008-04-22 Thread John Machin
Mike Driscoll wrote: Well you could always do something like this: output = ';'.join(roadList) Which will put single quotes on the ends. No, it doesn't. You are conflating foo and repr(foo). I suppose if you want to be silly, you could do this: output = '"%s"' % ';'.join(roadList) *IF*

Re: list manipulation

2008-04-22 Thread John Machin
Joe Riopel wrote: On Tue, Apr 22, 2008 at 4:55 PM, DataSmash <[EMAIL PROTECTED]> wrote: Hello, I have a list that looks like this: roadList = ["Motorways","Local","Arterial"] I want to apply some code so that the output looks like this: "Motorways;Local;Arterial" How can this be done with

Re: list manipulation

2008-04-22 Thread DataSmash
Joe & Mike, Thanks for your input! R.D. -- http://mail.python.org/mailman/listinfo/python-list

Re: list manipulation

2008-04-22 Thread Vlastimil Brom
2008/4/22, DataSmash <[EMAIL PROTECTED]>: > > Hello, > > I have a list that looks like this: > roadList = ["Motorways","Local","Arterial"] > > I want to apply some code so that the output looks like this: > "Motorways;Local;Arterial" > > ...in other words, I want each item in the list separated by

Re: list manipulation

2008-04-22 Thread Mike Driscoll
On Apr 22, 3:55 pm, DataSmash <[EMAIL PROTECTED]> wrote: > Hello, > > I have a list that looks like this: > roadList = ["Motorways","Local","Arterial"] > > I want to apply some code so that the output looks like this: > "Motorways;Local;Arterial" > > ...in other words, I want each item in the list

Re: list manipulation

2008-04-22 Thread Joe Riopel
On Tue, Apr 22, 2008 at 4:55 PM, DataSmash <[EMAIL PROTECTED]> wrote: > Hello, > > I have a list that looks like this: > roadList = ["Motorways","Local","Arterial"] > > I want to apply some code so that the output looks like this: > "Motorways;Local;Arterial" > How can this be done with the LE

list manipulation

2008-04-22 Thread DataSmash
Hello, I have a list that looks like this: roadList = ["Motorways","Local","Arterial"] I want to apply some code so that the output looks like this: "Motorways;Local;Arterial" ...in other words, I want each item in the list separated by a ';' and then the whole thing surrounded by quotes. How c

Re: List Manipulation

2006-07-05 Thread Gerard Flanagan
Dennis Lee Bieber wrote: > On 5 Jul 2006 04:37:46 -0700, "Gerard Flanagan" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > > > You can use a class rather than have lists of lists: > > > Are you sure you want to introduce classes into the mix, when simple > basics a

Re: List Manipulation

2006-07-05 Thread Gerard Flanagan
Roman wrote: > Dennis Lee Bieber wrote: > > On 4 Jul 2006 07:01:55 -0700, "Roman" <[EMAIL PROTECTED]> declaimed > > the following in comp.lang.python: > > > > > I would appreciate it if somebody could tell me where I went wrong in > > > the following snipet: > > > > > It would help if you gave

Re: List Manipulation

2006-07-05 Thread Bruno Desthuilliers
Mike Kent wrote: (snip) > p[j] does not give you a reference to an element inside p. Yes it does: >>> a = ['a'] >>> b = ['b'] >>> c = ['c'] >>> p = [a, b, c] >>> p[0] is a True >>> p[1] is b True >>> p[2] is c True >>> p[0].append('z') >>> a ['a', 'z'] >>> > It gives > you a new sublist contain

Re: List Manipulation

2006-07-05 Thread Iain King
Mike Kent wrote: > Roman wrote: > > Thanks for your help > > > > My intention is to create matrix based on parsed csv file. So, I would > > like to have a list of columns (which are also lists). > > > > I have made the following changes and it still doesn't work. > > > > > > cnt = 0 > > p=[[], []

Re: List Manipulation

2006-07-04 Thread Roman
below is the data I am trying to read "04""AS0042123BO" "AS 0042.123 ROYAL ELONG SEAT BO" "001610""A/S Fixtures" 0 $99.00 3.70"" "0042123" 11/20/2003 "24""AS0042001BK" "AS 0042.001 ROYAL EL*DISC BY MFG*BK" "001610""A/S Fixture

Re: List Manipulation

2006-07-04 Thread Bruno Desthuilliers
Roman a écrit : Roman, please stop top-posting and learn to quote. > Bruno Desthuilliers wrote: > >>Roman wrote: >>(please dont top-post - corrected) >> >>> >>>My intention is to create matrix based on parsed csv file. So, I >>>would like to have a list of columns (which are also lists). >> >>

Re: List Manipulation

2006-07-04 Thread Roman
Thanks for spending so much time with me. I had since made the following change. matrix = [[[] for l in range(len(list(reader)[:10]))] for c in range(len(list(reader)[7]))] for numline, line in enumerate(reader): for numcol, col in enumerate(line): matrix[numcol][numline] = col print

Re: List Manipulation

2006-07-04 Thread Bruno Desthuilliers
Roman wrote: (please dont top-post - corrected) > > Steven D'Aprano wrote: > >>On Tue, 04 Jul 2006 07:01:55 -0700, Roman wrote: >> >> (snip) >> >>>cnt = 0 >>>p=[] >>>reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", >>> quotechar="'", delimiter='\t') >>>fo

Re: List Manipulation

2006-07-04 Thread Roman
I am getting TypeError: unsubscriptable object when specifying for line in reader[:7]: Steven D'Aprano wrote: > On Tue, 04 Jul 2006 07:01:55 -0700, Roman wrote: > > > I would appreciate it if somebody could tell me where I went wrong in > > the following snipet: > > > > When I run I get no res

Re: List Manipulation

2006-07-04 Thread Bruno Desthuilliers
Roman wrote: (please dont top-post - corrected) > > Iain King wrote: > >>Roman wrote: >> >>>I would appreciate it if somebody could tell me where I went wrong in >>>the following snipet: >>> (snip) >>What are you trying to do here? p[:0] returns a new list, of all the >>elements in p up to ele

Re: List Manipulation

2006-07-04 Thread Roman
Nothing got printed. Could you tell me what would be pythonic version of what I am trying to do? Diez B. Roggisch wrote: > > p[j] does not give you a reference to an element inside p. It gives > > you a new sublist containing one element from p. You then append a > > column to that sublist. T

Re: List Manipulation

2006-07-04 Thread Diez B. Roggisch
> p[j] does not give you a reference to an element inside p. It gives > you a new sublist containing one element from p. You then append a > column to that sublist. Then, since you do nothing more with that > sublist, YOU THROW IT AWAY. Not correct. p = [[]] p[0].append(1) print p yields [[1

Re: List Manipulation

2006-07-04 Thread Mike Kent
Roman wrote: > Thanks for your help > > My intention is to create matrix based on parsed csv file. So, I would > like to have a list of columns (which are also lists). > > I have made the following changes and it still doesn't work. > > > cnt = 0 > p=[[], [], [], [], [], [], [], [], [], [], []] >

Re: List Manipulation

2006-07-04 Thread Sibylle Koczian
Roman schrieb: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result > > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", > quotechar="'", delimiter='\t') > for lin

Re: List Manipulation

2006-07-04 Thread Roman
Thanks for your help My intention is to create matrix based on parsed csv file. So, I would like to have a list of columns (which are also lists). I have made the following changes and it still doesn't work. cnt = 0 p=[[], [], [], [], [], [], [], [], [], [], []] reader = csv.reader(file("f:\we

Re: List Manipulation

2006-07-04 Thread Steven D'Aprano
On Tue, 04 Jul 2006 07:01:55 -0700, Roman wrote: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result What do you mean? Does it print None? > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="exc

Re: List Manipulation

2006-07-04 Thread Laszlo Nagy
Roman írta: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result > > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", > quotechar="'", delimiter='\t') > for line in

Re: List Manipulation

2006-07-04 Thread Iain King
Roman wrote: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result > > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", > quotechar="'", delimiter='\t') > for line i

Re: List Manipulation

2006-07-04 Thread Mike Kent
Roman wrote: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result > > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", > quotechar="'", delimiter='\t') > for line in

List Manipulation

2006-07-04 Thread Roman
I would appreciate it if somebody could tell me where I went wrong in the following snipet: When I run I get no result cnt = 0 p=[] reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", quotechar="'", delimiter='\t') for line in reader: if cnt > 6: