On Nov 21, 2007, at 4:30 AM, Alan Bourke wrote:
>> Of course, you have been able to do that in Python for several years
>> now.
>>
> I thought it was a case of sending a string into an Execute statement,
> is there another way ?
You can do that if you're looking at data in a database server,
sure. But what if you have the data locally and want to do the
equivalent of a SQL-SELECT on it? A Python feature called 'list
comprehensions' allows you to take any collection of items and create
a new list from that. Simple examples:
startlist = [1,2,3,4,5]
squares = [x**2 for x in startlist]
=> [1, 4, 9, 16, 25]
evensquares = [x**2 for x in startlist
if x%2 == 0]
=> [4, 16]
names = ["Ed", "Alan", "Paul", "Dave", "Hubert"]
lownames = [nm.lower() for nm in names]
=> ["ed", "alan", "paul", "dave", "hubert"]
noA = [nm.replace("a", "") for nm in names
if len(nm) < 5]
=> ['Ed', 'Aln', 'Pul', 'Dve']
These examples are just with strings and integers, but it works with
anything in Python, even the most complex objects you can create.
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.