How to find elements of a list are subset of string using python
Question: I am a Molecular Biologist and new to programming, so excuse me for my
language. I am working with python.

Example:

    
    
    string = "gctatagcgttatatactagcctatagctata"
    
    list = ["gtagctaggac", "mptalltruiworw", "12365478995", "nvncmvncmvncmvn"]
    

now coming to question  
I want to know a method which can discover that

    
    
    for element in list:
      if element is subset of string (in any order)
      return element
    

In above example the answer should be

    
    
    gtagctaggac
    


Answer: Rather than spend time generating permutations, compare the number of letters
in the list element and the string. Note that this code doesn't check for
letters in the string that are not in the pattern.

    
    
    string = "gctatagcgttatatactagcctatagctata"
    list = ["gtagctaggac", "mptalltruiworw", "12365478995", "nvncmvncmvncmvn"]
    
    from collections import defaultdict
    
    def count_letters(string):
        counts = defaultdict(int)
        for letter in string:
            counts[letter] += 1
        return counts
    
    sc = count_letters(string)
    
    for element in list:
        counts = count_letters(element)
        if all([sc[letter] >= counts[letter] for letter in counts]):
            print "Found", element
    

As a matter of style, it's better not to use the names of built-in classes
like "list" and "string".

