RE: nested tuple slice
maybe list(tuple)[0:2])) will get you what you want but I don’t know how to change it back to a tuple. I’m just starting out but I would be interested also. mark -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of dimitri pater Sent: Tuesday, April 12, 2005 5:49 PM To: python-list@python.org Subject: nested tuple slice hello! I want to change a nested tuple like: tuple = (('goat', 90, 100), ('cat', 80, 80), ('platypus', 60, 800)) into: tuple = (('goat', 90), ('cat', 80), ('platypus', 60)) in other words, slice the first elements of every index Any ideas on how to do this in an elegant, pythonic way? Best regards, Dimitri -- http://mail.python.org/mailman/listinfo/python-list
FW: FW: Python help group
This is a follow up question To the previous question About sorting that I sent for my friend. -Original Message- From: Tan, Heap Ho Sent: Tuesday, March 22, 2005 2:06 PM To: Leeds, Mark Subject: RE: FW: Python help group How can you speed it? Does anyone know if pytable can take non-homogeneous objects type? -Original Message- From: Leeds, Mark Sent: Tuesday, March 22, 2005 1:39 PM To: Tan, Heap Ho Subject: FW: FW: Python help group -Original Message- From: Swaroop C H [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 22, 2005 1:25 PM To: Leeds, Mark Cc: python-list@python.org Subject: Re: FW: Python help group On Tue, 22 Mar 2005 13:15:15 -0500, Leeds, Mark wrote: > I want to do a sort on a list of objects based on a similar attributes in > each object for example time of creation of this object. >>> >>> class Student: ... def __init__(self, name, age): ... self.name = name ... self.age = age ... >>> >>> students = [Student('John', 18), Student('Jill', 17)] >>> students.sort(lambda x,y: cmp(x.age, y.age)) >>> [student.name for student in students] ['Jill', 'John'] >>> See `help(list.sort)` for details. -- Swaroop C H Blog: http://www.swaroopch.info Book: http://www.byteofpython.info -- http://mail.python.org/mailman/listinfo/python-list
FW: Python help group
Can someone help me with below ? It’s not my question but I will forward any answers to my friend who I am sending this for. Mark -Original Message- From: Tan, Heap Ho Sent: Tuesday, March 22, 2005 1:11 PM To: Leeds, Mark Subject: Python help group I want to do a sort on a list of objects based on a similar attributes in each object for example time of creation of this object. Is there a simple way to do this? Thank -Original Message- From: Leeds, Mark Sent: Monday, March 21, 2005 5:35 PM To: Tan, Heap Ho Cc: Leeds, Mark Subject: crontab -- http://mail.python.org/mailman/listinfo/python-list
newbie:unique problem
I have a function uniqueList that is below : Def uniqueList(origList): nodups= {} for temp in origList: nodups[temp] = None returns nodups.keys() When used in the following context : industryList = uniqueList(jpbarradata[group]) where jpbarradata[group] might look like [“AAA BC”,BBB KK”,”CCC TD”,”AAA KP”,”CCC TD”] ,the function works in the sense that it would return [“AAA BC”,”BBB KK”,”CCC TD”,AAA KP”] because CCC TD is duplicated. But, I also want it to get rid of the AAA KP because there are two AAA’s even though the last two letters are different. It doesn’t matter to me which one is gotten rid of but I don’t know how to change the function to handle this ? I have a feeling it’s not that hard though ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
newbie : modifying a string in python
I want to modify a string in the following way : for s in stks: s = s.strip() if ( s[-2:] == ‘GR’ ): s[-2:]= ‘GF’ so, if the last two characters are GR, I want to change them to GF ( there will be other if statements also but I am just putting this one here for simplicity ). I think the code is fine but I vaguely remember reading somewhere in the documentation that python strings can’t be changed ( only elements of lists can be ) ?. Is that true or is it okay to do the above. . thanks -- http://mail.python.org/mailman/listinfo/python-list
using the set command
Do I have to import something In order to use the set command ? I am trying to use it but I keep getting an error. Mark -- http://mail.python.org/mailman/listinfo/python-list
novice question
I have a dictionary grp that has lists for each element ( excuse my terminology if it’s incorrect). So gname might be automobiles, finance, construction etc and grp[gname] is a list and this list has elements that are strings such as [“AAA”,”BBB”,”AAA”,”CCC”] Is there a quick way to loop through the grp dictionary and reduce the lists so that each only contains unique elements ? thanks -- http://mail.python.org/mailman/listinfo/python-list
FW: list reduction
I have a structure in python that I think is a list with elements .Cap and .Ticker where Cap is a float and Ticker is string. So, I reference things like industrylist[i].cap and industrylist[i].ticker and this works fine. What I want to do is reduce the list so that it only keeps elements of the list for which the cap is less than x where x is known ? I think I need to use filter and lambda but i’ve looked in the documentation and I haven’t been able to figure out how to use it. Apologies if this is a bad question. Thanks -- http://mail.python.org/mailman/listinfo/python-list
quick question
I have a string variable say “8023 “ and I want to get rid of the beginning And ending quotes. I’ve tried different things But haven’t had any success. I’m definitely a python hacker and Not an expert. Thanks. Mark -- http://mail.python.org/mailman/listinfo/python-list