[Tutor] Searching string value in db

lumbricus@gmx.net lumbricus@gmx.net
Wed Nov 27 16:38:02 2002


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 für 1 ct/ Min. surfen!