Fixing return format for my function
<p>The code for my function works correctly, but it is not returning the function in the format I would like. The function counts seed values in a 2nd sequence and then is supposed to return the seed counts as a list of integers. It is returning the seed counts but on separate lines rather then in a list. Here is my code and what its returning in command prompt.</p>

<pre><code>    def count_each(seeds,xs):
        for c in seeds:
            count=0
        for d in xs:
            if c==d:
                count=count+1
        print ([count])
</code></pre>

<p>count_each([10,20],[10,20,30,10])</p>

<p>count_each([4,8],[1,2,4,4,4,8,8,10])</p>

<p>In command prompt, I would like this function to print [2,1] for count_each([10,20],[10,20,30,10]) and [3,2] for count_each([4,8],[1,2,4,4,4,8,8,10]) but instead it is printing each seed value on its own line like so </p>

<p><a href="http://i.stack.imgur.com/vXAd3.png" rel="nofollow">http://i.stack.imgur.com/vXAd3.png</a></p>

<p>In the picture above it prints [2], [1], [3], and [2] on separate lines when it should instead print just two lines of [2,1] and [3,2] for the two sequences. How can I have the function return the seed values for each sequence as a list instead of having the values on separate lines.</p>

<p>Edit: I need to accomplish this without importing from other modules and with the simplest code possible.</p>

<p>I think your code does not work. Try this:</p>

<pre><code>def count_each(seeds,xs):
    from collections import Counter
    counter_dict = dict(Counter(xs))
    count = []
    for s in seeds:
        count.append(counter_dict[s])
    print count

if __name__ == "__main__":
    count_each([10,20],[10,20,30,10])
    count_each([4,8],[1,2,4,4,4,8,8,10])
</code></pre>

<p>Basically, <code>Counter</code> gives you a count for each unique element in a list.</p>

<h1>Update:</h1>

<p>Just found a <code>count</code> method for Python's <code>list</code>. The code is as follows:</p>

<pre><code>def count_each(seeds,xs):
    from collections import Counter
    count = []
    for s in seeds:
        count.append(xs.count(s))
    print count
</code></pre>

python list format sequence