Ok.  I think I understand and I happen to be up at 1:30 my time so
here 
is the solution as I understand the problem.  This is a very common 
problem and has  a fairly easy solution.  You can then take
adict.keys() 
which returns a list of unique elements.  Good Luck

import random
l=[random.randrange(1,20) for x in range(100)]
l
[7, 18, 17, 17, 6, 11, 14, 9, 4, 16, 2, 9, 3, 13, 4, 2, 5, 15, 15, 3,
3, 
11, 18, 12, 6, 8, 15, 3, 7, 9, 9, 7, 12, 11, 11, 9, 19, 19, 15, 2,
17, 
18, 16, 8, 15, 3, 19, 19, 19, 1, 3, 17, 3, 8, 16, 1, 5, 19, 17, 16,
19, 
6, 3, 8, 16, 11, 12, 7, 10, 13, 13, 11, 6, 2, 18, 15, 17, 8, 12, 13,
5, 
12, 2, 19, 2, 19, 7, 10, 4, 14, 15, 14, 5, 1, 16, 1, 9, 10, 17, 12]
adict={}
for x in l:
    if adict.has_key(x):
    #then there is already an item
        adict[x]+=1 #increment the count by one
    else: #there is no key the item hasn't been seen
        adict[x]=1 #there is one instance so far
   
adict
{1: 4, 2: 6, 3: 8, 4: 3, 5: 4, 6: 4, 7: 5, 8: 5, 9: 6, 10: 3, 11: 6,
12: 
6, 13: 4, 14: 3, 15: 7, 16: 6, 17: 7, 18: 4, 19: 9}

Srinivas Iyyer wrote:

>Dear Jacob, thank you for your suggestion.
>
>however, i think my question was not clear. what i
>meant to ask in my previous question was, how to know
>which elements repeated and how many times they were
>repeated. 
>
>while my question was flying, i did a small test:
>
>took a list:
>  
>
>>>>a
>>>>        
>>>>
>[1, 1, 2, 3, 4, 2, 2]
>
>wanted to know which elements repeated and how many
>times:
>


                
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to