[Tutor] Searching string value in db

Doug.Shawhan@gecits.ge.com Doug.Shawhan@gecits.ge.com
Wed Nov 27 16:43:08 2002


Good advice!

I did get mine to work with judicious use of string.upper().

*blush* 

-----Original Message-----
From: lumbricus@gmx.net [mailto:lumbricus@gmx.net]
Sent: Wednesday, November 27, 2002 3:37 PM
To: tutor@python.org
Subject: Re: [Tutor] Searching string value in db


Hi!

> I have a database in the following format:
> 
> 'key' : 'FOO, data, data' <--Regular old string with commas...

Is 'FOO' always at the start?
 
> however: 
> 
> >>> for each in db.keys():
> 	if string.find(db[each], 'FOO') != -1:
> 		print each, db[each]

Then try this:

for each in db.keys():
    if db[each].split(',')[0] == 'FOO': print each, db[each] 

You may also store the list returned by split() for 
further processing. All untested.

Another way may be:

for each in db.keys():
    if db[each][:3] == "FOO":
        pass
    
> Thanks folks!
> 
> d

HTH, J"o!

-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr fur 1 ct/ Min. surfen!


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor