Task:

Write a method that will search an array of strings for all strings that contain another string, ignoring capitalization. Then return an array of the found strings.

The method takes two parameters, the query string and the array of strings to search, and returns an array.

If the string isn't contained in any of the strings in the array, the method returns an array containing a single string: "Empty" (or Nothing in Haskell, or "None" in Python)

Examples:

If the string to search for is "me", and the array to search is ["home", "milk", "Mercury", "fish"], the method should return ["home", "Mercury"].

Kata's link: Partial Word Searching

Best Practices

Py First:

def word_search(query, seq):
    return [x for x in seq if query.lower() in x.lower()] or ["None"]

Py Second:

import re

def word_search(query, seq):
    return [w for w in seq if re.search(query, w, re.I)] or ['None']

Py Third:

def word_search(query, seq):
    query = query.lower()
    result = [x for x in seq if query in x.lower()]
    return result if result else ['None']

results matching ""

    No results matching ""