I am trying to solve a class assignment as listed below
Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:
seq = ['soup','dog','salad','cat','great']
should be filtered down to:
['soup','salad']
I wrote the following two sets of code...
seq = ['soup', 'dog','salad', 'cat', 'great']
result = filter (lambda test: test[0] == "s",seq)
print (result)
seq = ['soup', 'dog','salad', 'cat', 'great']
def checkf (input):
if input[0]=='s':
a = "TRUE"
return(a)
test = seq[0]
result = filter (checkf(test),seq)
print (result)
Both codes give a strange answer filter object at 0x112aa06d8 as if it is returning a memory address in hexadecimal... What's wrong?