I'm trying to find the words starting with character "s". I have a list of strings (seq) to check.
seq = ['soup','dog','salad','cat','great']
sseq = " ".join(seq)
filtered = lambda x: True if sseq.startswith('s') else False
filtered_list = filter(filtered, seq)
print('Words are:')
for a in filtered_list:
print(a)
The output is:
Words are:
soup
dog
salad
cat
great
Where I see the entire list. How can I use lambda and filter() method to return the words starting with "s" ? Thank you
[word for word in seq if word.lower().startswith('s')]filteredignore its argument?sseqin the function, instead ofx, the argument? Why are you creatingsseqin the first place?