Re: List problem

2012-12-03 Thread John Gordon
In <8c0a3ea9-2560-47eb-a9c7-3770e41fe...@googlegroups.com> subhabangal...@gmail.com writes: > Dear Group, > I have a list of the following pattern, > [("''", "''"), ('Eastern', 'NNP'), ('Army', 'NNP'), ('Commander', 'NNP'), (= > 'Lt', 'NNP'), ('Gen', 'NNP'), ('Dalbir', 'NNP'), ('Singh', 'NNP'),

Re: List problem

2012-12-03 Thread Neil Cerutti
On 2012-12-02, Thomas Bach wrote: > On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote: >> >> len([x for x in l if x[1] == 'VBD']) >> > > Another way is > > sum(1 for x in l if x[1] == 'VBD') > > which saves the list creation. To also index them: vbdix = [i for i, a in emumerate(l) if a

Re: List problem

2012-12-02 Thread subhabangalore
On Sunday, December 2, 2012 9:29:22 PM UTC+5:30, Thomas Bach wrote: > On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote: > > > > > > len([x for x in l if x[1] == 'VBD']) > > > > > > > Another way is > > > > sum(1 for x in l if x[1] == 'VBD') > > > > which saves the list creati

Re: List problem

2012-12-02 Thread Thomas Bach
On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote: > > len([x for x in l if x[1] == 'VBD']) > Another way is sum(1 for x in l if x[1] == 'VBD') which saves the list creation. Regards, Thomas. -- http://mail.python.org/mailman/listinfo/python-list

Re: List problem

2012-12-02 Thread Lutz Horn
Him Am 02.12.2012 um 16:03 schrieb subhabangal...@gmail.com: > I have a list of the following pattern, > > [("''", "''"), ('Eastern', 'NNP'), ('Army', 'NNP'), ('Commander', 'NNP'), > ('Lt', 'NNP'), ('Gen', 'NNP'), ('Dalbir', 'NNP'), ('Singh', 'NNP'), ('Suhag', > 'NNP'), ('briefed', 'VBD'), ('th

Re: List Problem

2012-09-23 Thread Chris Angelico
On Mon, Sep 24, 2012 at 10:56 AM, Littlefield, Tyler wrote: > I've not been following this thread fully, but why not just use x=list(y) to > copy the list? > The issue is that when you assign i=[1,2,3] and then j = i, j is just a > reference to i, which is why you change either and the other chang

Re: List Problem

2012-09-23 Thread Littlefield, Tyler
On 9/23/2012 3:44 PM, jimbo1qaz wrote: On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: I have a nested list. Whenever I make a copy of the list, changes in one affect the other, even when I use list(orig) or even copy the sublists one by one. I have to manually copy each cell

Re: List Problem

2012-09-23 Thread jimbo1qaz
On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, even when I use list(orig) or even copy the sublists one by > one. I have to manually copy each cell over for it to work. > > Link to br

Re: List Problem

2012-09-23 Thread Steven D'Aprano
On Sun, 23 Sep 2012 14:31:48 -0700, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, Then you aren't making a copy. py> first_list = [1, 2, 3] py> second_list = first_list # THIS IS NOT A COPY py> second_list.append() py> print

Re: List Problem

2012-09-23 Thread Dave Angel
On 09/23/2012 05:44 PM, jimbo1qaz wrote: > On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: >> I have a nested list. Whenever I make a copy of the list, changes in one >> affect the other, even when I use list(orig) or even copy the sublists one >> by one. I have to manually copy

Re: List Problem

2012-09-23 Thread Chris Angelico
On Mon, Sep 24, 2012 at 7:44 AM, jimbo1qaz wrote: > On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: >> I have a nested list. Whenever I make a copy of the list, changes in one >> affect the other, even when I use list(orig) or even copy the sublists one >> by one. I have to manu

Re: List Problem

2012-09-23 Thread Oscar Benjamin
On 23 September 2012 22:31, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, even when I use list(orig) or even copy the sublists one > by one. I have to manually copy each cell over for it to work. > Link to broken code: http://jimbo

Re: List Problem

2012-09-23 Thread jimbo1qaz
On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, even when I use list(orig) or even copy the sublists one by > one. I have to manually copy each cell over for it to work. > > Link to br

Re: list problem...

2010-09-29 Thread Shashwat Anand
On Thu, Sep 30, 2010 at 3:20 AM, Rog wrote: > On Wed, 29 Sep 2010 05:52:32 -0700, bruno.desthuilli...@gmail.com wrote: > > > On 29 sep, 14:17, Steven D'Aprano > > > wrote: > >> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > >> > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > >> > >

Re: list problem...

2010-09-29 Thread Rog
On Wed, 29 Sep 2010 05:52:32 -0700, bruno.desthuilli...@gmail.com wrote: > On 29 sep, 14:17, Steven D'Aprano > wrote: >> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: >> > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: >> >> >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >> >>> Hi al

Re: list problem...

2010-09-29 Thread bruno.desthuilli...@gmail.com
On 29 sep, 14:17, Steven D'Aprano wrote: > On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > >>> Hi all, > >>> Have been grappling with a list problem for hours... a = [2, 3, 4, > >>> 5

Re: list problem...

2010-09-29 Thread Steven D'Aprano
On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >>> Hi all, >>> Have been grappling with a list problem for hours... a = [2, 3, 4, >>> 5,.] >>> b = [4, 8, 2, 6,.] >>> Basicly I am

Re: list problem...

2010-09-28 Thread Shashwat Anand
On Wed, Sep 29, 2010 at 1:15 AM, rog wrote: > Shashwat Anand wrote: > > >> >> On Wed, Sep 29, 2010 at 12:14 AM, Rog > r...@pynguins.com>> wrote: >> >>Hi all, >>Have been grappling with a list problem for hours... >>a = [2, 3, 4, 5,.] >>b = [4, 8, 2, 6,.] >>Basicly I am

Re: list problem...

2010-09-28 Thread Rog
On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >> Hi all, >> Have been grappling with a list problem for hours... a = [2, 3, 4, >> 5,.] >> b = [4, 8, 2, 6,.] >> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and

Re: list problem...

2010-09-28 Thread geremy condra
On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > Hi all, > Have been grappling with a list problem for hours... > a = [2, 3, 4, 5,.] > b = [4, 8, 2, 6,.] > Basicly I am trying to place a[0], b[0] in a seperate list > IF a[2] and b[2] is present. > I have tried sets, zip etc with no success.

Re: list problem...

2010-09-28 Thread Shashwat Anand
On Wed, Sep 29, 2010 at 12:14 AM, Rog wrote: > Hi all, > Have been grappling with a list problem for hours... > a = [2, 3, 4, 5,.] > b = [4, 8, 2, 6,.] > Basicly I am trying to place a[0], b[0] in a seperate list > IF a[2] and b[2] is present. > You are not exactly clear with your proble

Re: List Problem

2008-12-09 Thread Robert Lehmann
On Tue, 09 Dec 2008 21:40:08 -0800, dongzhi wrote: > I have one problem for List. Like that: > > format='just "a" ""little"" test' > part = format.split('"') > print part > > the result is : ['just ', 'a', ' ', '', 'little', '', ' test'] > > the list part have 7 element. > > If I execute part[

Re: List Problem

2008-12-09 Thread dongzhi
On Dec 10, 2:00 pm, "James Mills" <[EMAIL PROTECTED]> wrote: > On Wed, Dec 10, 2008 at 3:40 PM, dongzhi <[EMAIL PROTECTED]> wrote: > > If I execute part[1], I have got  'a'. If I execute part[2], I have > > got ' '. But, if I execute part[1::2], I have got ['a', '', '']. I > > don't know why. Pleas

Re: List Problem

2008-12-09 Thread James Mills
On Wed, Dec 10, 2008 at 3:40 PM, dongzhi <[EMAIL PROTECTED]> wrote: > If I execute part[1], I have got 'a'. If I execute part[2], I have > got ' '. But, if I execute part[1::2], I have got ['a', '', '']. I > don't know why. Please tell me why. Perhaps you meant: part[1:2] pydoc list This will

Re: List problem

2007-12-16 Thread Mel
Alan Bromborsky wrote: > I wish to create a list of empty lists and then put something in one of > the empty lists. Below is what I tried, but instead of appending 1 to > a[2] it was appended to all the sub-lists in a. What am I doing wrong? > > a = 6*[[]] > >>> a > [[], [], [], [], [], []] >

Re: List problem

2006-08-25 Thread Georg Brandl
[EMAIL PROTECTED] wrote: > For example i write the following code in the Python command line; > list = ['One,Two,Three,Four'] > > Then enter this command, which will then return the following; > > ['One,Two,Three,Four'] This is already wrong. Assignments do not return anything. Georg -- h

Re: List problem

2006-08-24 Thread Larry Bates
[EMAIL PROTECTED] wrote: > For example i write the following code in the Python command line; > list = ['One,Two,Three,Four'] > > Then enter this command, which will then return the following; > > ['One,Two,Three,Four'] > > > Now the problem, reading through the Python tutorial's, it desc

Re: List problem

2006-08-24 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > For example i write the following code in the Python command line; > list = ['One,Two,Three,Four'] > > Then enter this command, which will then return the following; > > ['One,Two,Three,Four'] > > > Now the problem, reading through the Python tutorial's, it des

Re: list problem

2006-07-26 Thread placid
Thank you all for the replies, i now have a better solution. Cheers -- http://mail.python.org/mailman/listinfo/python-list

Re: list problem

2006-07-26 Thread Paul Rubin
"placid" <[EMAIL PROTECTED]> writes: > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] > > the second list contains strings that are identical to the first list, > so lets say the second list contains the following > > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX6'] I think you meant list2 for the

Re: list problem

2006-07-26 Thread Gerard Flanagan
Gerard Flanagan wrote: > placid wrote: > > Hi all, > > > > I have two lists that contain strings in the form string + number for > > example > > > > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] > > > > the second list contains strings that are identical to the first list, > > so lets say the sec

Re: list problem

2006-07-26 Thread Gerard Flanagan
placid wrote: > Hi all, > > I have two lists that contain strings in the form string + number for > example > > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] > > the second list contains strings that are identical to the first list, > so lets say the second list contains the following > > >>> lis

Re: list problem

2006-07-26 Thread Simon Forman
placid wrote: > > But there may be other characters before XXX (which XXX is constant). A > better example would be, that string s is like a file name and the > characters before it are the absolute path, where the strings in the > first list can have a different absolute path then the second list

Re: list problem

2006-07-26 Thread zutesmog
placid wrote: > Hi all, > > I have two lists that contain strings in the form string + number for > example > > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] > > the second list contains strings that are identical to the first list, > so lets say the second list contains the following > > >>> lis

Re: list problem

2006-07-26 Thread bearophileHUGS
placid: This may be a solution: l1 = ['acXXX1', 'XXX2', 'wXXX3', 'kXXX5'] l2 = [ 'bXXX1', 'xXXX2', 'efXXX3', 'yXXX6', 'zZZZ9'] import re findnum = re.compile(r"[0-9]+$") s1 = set(int(findnum.search(el).group()) for el in l1) s2 = set(int(findnum.search(el).group()) for el in l2) nmax = max(max(s

Re: list problem

2006-07-25 Thread Simon Forman
placid wrote: > Simon Forman wrote: > > placid wrote: > > > Hi all, > > > > > > I have two lists that contain strings in the form string + number for > > > example > > > > > > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] > > > > > > the second list contains strings that are identical to the first

Re: list problem

2006-07-25 Thread placid
Simon Forman wrote: > placid wrote: > > Hi all, > > > > I have two lists that contain strings in the form string + number for > > example > > > > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] > > > > the second list contains strings that are identical to the first list, > > so lets say the second

Re: list problem

2006-07-25 Thread Simon Forman
Simon Forman wrote: > Finally, you can say: > > for i in xrange(1,10): > s = "XXX1%04i" % i > if s not in list1 and s not in list2: > print s > > HTH, > ~Simon D'oh! Forgot to break. for i in xrange(1,10): s = "XXX1%04i" % i if s not in list1 and s not in list2: p

Re: list problem

2006-07-25 Thread Simon Forman
placid wrote: > Hi all, > > I have two lists that contain strings in the form string + number for > example > > >>> list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] > > the second list contains strings that are identical to the first list, > so lets say the second list contains the following > > >>> list

Re: list problem 4 newbie

2006-06-26 Thread manstey
Thanks very much. Deepcopy works fine, as does reversed(b). I thought I needed the index number but I didn't. Duncan Booth wrote: > manstey wrote: > > > for index in reversed(range(0,len(a)-1)): > >if '75' in b[index][1]: > > b[index][1].remove('75') > > b[index][1].append('99')

Re: list problem 4 newbie

2006-06-26 Thread Duncan Booth
manstey wrote: > for index in reversed(range(0,len(a)-1)): >if '75' in b[index][1]: > b[index][1].remove('75') > b[index][1].append('99') > What on earth is all that messing around in the for loop intended to do? If you want a range from len(a)-2 to 0 inclusive then just do it i

Re: list problem 4 newbie

2006-06-25 Thread vaibhav
Hi, if u check the id's of a and b lists and also its elements, you will obeserve that the id's of a and b have changed but id's of their elements have not changed. If you make a deep copy of the list a and then make your changes in that list, it shud work. this can be done using the copy module