Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

Is there an equivalent way to search a set that only contains unique string elements for a word that starts with an arbitrary substring? similar to a list search like this: for word in list: if word[:len(substring)] == substring:

OpenStudy (anonymous):

this is python btw

OpenStudy (anonymous):

Try using filter. filter(sequence, lambda str: str.startswith(substring)) That will return a list of words that start with substring.

OpenStudy (anonymous):

Sorry my answer gave the wrong argument order. Try this: filter(lambda word: word.startswith(substring), set) Also I don't see why your original post won't work for sets as well as lists.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!