Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Location
    Philippines
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    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 **


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •