Python code that will find words made out of specific letters. Any subset of the letters could be used

后端 未结 4 616
滥情空心
滥情空心 2020-12-22 08:31

If I have a list of words in the variable words and a list of letters in the variable letters, how can I find all the words that can be made up out of the letters in letters

4条回答
  •  长情又很酷
    2020-12-22 09:11

    Use regular expressions:

    >>> import re
    >>> m = re.compile('^[abilrstu]+$')
    >>> m.match('australia') is not None
    True
    >>> m.match('dummy') is not None
    False
    >>> m.match('australian') is not None
    False
    

提交回复
热议问题