l=["cat","dog","doll","rat"]
prefix="do"
output=[]
for word in l:
if prefix==word[0:len(prefix)]:
output.append(word)
print(output)
Output
['dog', 'doll']
=== Code Execution Successful ===
In this program prefix "do" match with list element dog,doll.so output list the word that match with prefix is [dog,doll].
Here prefix is do
And length of prefix is 2 that match with list element.
0 Comments