[Tutor] How to create a dictionary for ount elements
Mark Lawrence
breamoreboy at yahoo.co.uk
Wed Jun 4 00:47:38 CEST 2014
On 03/06/2014 17:24, jarod_v6 at libero.it wrote:
> HI there!!!
> I have afile like this:
> file.txt
> programs sample gene
> program1 sample1 TP53
> program1 sample1 TP53
> program1 sample2 PRNP
> program1 sample2 ATF3
> program2 sample1 TP53
> program2 sample1 PRNP
> program2 sample2 TRIM32
> program2 sample2 TLK1
> program2 sample2 KIT
>
>
> with open("prova.csv") as p:
> for i in p:
> ...: lines = i.rstrip("\n").split("\t")
> ...: print lines
> ...:
> ['programs ', 'sample', 'gene', 'values']
> ['program1', 'sample1', 'TP53', '2']
> ['program1', 'sample1', 'TP53', '3']
> ['program1', 'sample2', 'PRNP', '4']
> ['program1', 'sample2', 'ATF3', '3']
> ['program2', 'sample1', 'TP53', '2']
> ['program2', 'sample1', 'PRNP', '5']
> ['program2', 'sample2', 'TRIM32', '4']
> ['program2', 'sample2', 'TLK1', '4']
>
>
> I want to create a dictionary with set data with the names of the genes:
>
> example:
> dic = {}
>
>
> dic['program1-sample1] = set(TP53)
> dic['program1-sample2] = set(TP53,PRNP,ATF3)
>
> So If I have a dictionary like that I can compare two set I will compare the
> capacity of the programs in function of the gene show.
> Thanks in advance for your help!
>
Is this of any use to you
https://docs.python.org/3/library/collections.html#collections.Counter ?
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
More information about the Tutor
mailing list