2

Code:

def find(string_list, search):
    new_list = []
    for i in string_list:
        if search in i:
            new_list.append(i)
    print(new_list)

print(find(['she', 'sells', 'sea', 'shells', 'on', 'the', 'sea-shore'], 'he'))

Returns:

['she', 'shells', 'the']
None
thegrinner
  • 11,546
  • 5
  • 41
  • 64

2 Answers2

3

You're not returning anything, so the function returns None by default. Also, you can do this in a more Pythonic way:

def find(string_list, search):
    return [i for i in string_list if search in i]

This is called a list comprehension, and you can read more about them here.

arshajii
  • 127,459
  • 24
  • 238
  • 287
2

This is the solution

def find(string_list, search):
    new_list = []
    for i in string_list:
        if search in i:
            new_list.append(i)
    return new_list

print(find(['she', 'sells', 'sea', 'shells', 'on', 'the', 'sea-shore'], 'he'))
Smarties89
  • 561
  • 3
  • 10