famguy74 famguy74 - 1 month ago 9
Python Question

Counting seed values from first sequence in second sequence

If a function is given a sequence

seeds
of seed values, it needs to count for every single seed value the number of times they show up in the 2nd sequence
xs
. Then it should return the counts as a list of integers, in the same order of the seed values. If
seeds
includes duplicated values, keep duplicated counts in the returned list. For example,
count_each([10,20],[10,20,50,20,40,20])
should return
[1,3]
and
count_each('aeiou','encyclopedia') should return [1,2,1,1,0]
.

I'm stuck on how to program this function. This is what I have so far but I can't figure out how exactly I would count the number of seed values in the second sequence and not just check if the values exist. Any help on this would be appreciated.

def count_each(seeds,xs):

if seeds in xs:
if seeds == True
return seeds
elif seeds == False
return None

Answer
def count_letter(seeds,xs):
    for c in seeds:
        count=0
        for d in xs:
            if c==d:
                count=count+1
        print (c,"Occured ",count,"times")

count_letter([10,20],[10,20,30,10])
count_letter('aeiou','encyclopedia')