On Wed, Sep 15, 2010 at 1:14 PM, kumar s <[email protected]> wrote:
> Hi group:
>
> I have a list:
>
> k = ['T', 'C', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T', 'T', 'C',
> 'T',
> 'T', 'T', 'C', 'C', 'T', 'T', 'T', 'C', 'T', 'T', 'T', 'T', 'T', 'T']
>
> the allowed elements are A or T or G or C. List can have any number of A or
> T or
> G or C
>
> My aim is to get a string ouput with counts of each type A or T or G or C.
>
> A:0\tT:23\tG:0\tC:6
>
> from the above example, I could count T and C and since there are no A and
> G, I
> want to print 0 for them. I just dont know how this can be done.
>
>>> k = ['T', 'C', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T', 'T',
'C', 'T', 'T', 'T', 'C', 'C', 'T', 'T','T', 'C', 'T', 'T', 'T', 'T', 'T',
'T']
>>> "\t".join(x+":"+str(k.count(x)) for x in 'ATGC')
'A:0\tT:23\tG:0\tC:6'
>
>
>
>
> >>> d = {}
> >>> for i in set(k):
> ... d[i] = k.count(i)
> ...
> >>> d
> {'C': 6, 'T': 23}
>
>
> >>> for keys,values in d.items():
> ... print keys+'\t'+str(d[keys])
> ...
> C 6
> T 23
>
> the other way i tried is:
> >>> k.count('A'),k.count('T'),k.count('G'),k.count('C')
> (0, 23, 0, 6)
>
>
> how can I get counts for those elements not represented in list and print
> them. appreciate your help.
>
>
>
> thanks
> kumar
>
>
>
>
>
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
~l0nwlf
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor