Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2011, 07:14 AM   PM User | #1
RamaJin
New Coder

 
Join Date: Feb 2009
Location: Philippines
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
RamaJin is an unknown quantity at this point
Searching/Matching List like SQL

Hi and Good Day,

I would like to ask if I can search a list with the same concept like "select blah from bled like '%search%'". I have a table of words and I populate it to a list and loop from there instead of query every word back and forth within the table

ex.
Code:
l = ['Johns','Luke John Doe','DoeJanice']
search = 'John'
if i do a:
if search in l: = will result to false
is there a way to match list in a like format?
RamaJin is offline   Reply With Quote
Old 08-12-2011, 03:14 PM   PM User | #2
Samhain13
Regular Coder

 
Samhain13's Avatar
 
Join Date: Aug 2008
Location: Pilipinas
Posts: 165
Thanks: 4
Thanked 18 Times in 18 Posts
Samhain13 is on a distinguished road
Like this?
Code:
l = ['Johns','Luke John Doe','DoeJanice']
search = 'John'
# Use list comprehension to generate a list of results.
results = [x for x in l if search in x]
Result:
Code:
['Johns', 'Luke John Doe']
__________________
I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
** Independent Multimedia Artist in Pasig **
Samhain13 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:55 AM.


Advertisement
Log in to turn off these ads.