01 A Counting DNA Nucleotides
Problem
A string is simply an ordered collection of symbols selected from some alphabet and formed into a word; the length of a string is the number of symbols that it contains.
An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G', and 'T') is "ATGCTTCAGAAAGGTCTTACG."
Given: A DNA string ss of length at most 1000 nt.
Return: Four integers (separated by spaces) counting the respective number of times that the symbols 'A', 'C', 'G', and 'T' occur in ss.
Sample Dataset
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC
Sample Output
20 12 17 21 方法一:
f = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
for i in f:
b = list(f) # 把‘AAA’变成 ['A','A'',A']
c = {}
for i in b:
c[i] = b.count(i) # 把key 和value 写入字典,如 A:1
print (c.values()) # 最后的结果为 [20,12,21,17]
方法二:
f = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
counts = []
for i in ['A','C','G','T']: # 把输出的顺序定好
counts.append(f.count(i))
print ('\t'.join(map(str, counts))) #map() 这里的意思是吧输出的[20,12,17,21]变为 20 12 17 21
01 A Counting DNA Nucleotides的更多相关文章
- 1.Counting DNA Nucleotides
Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...
- JELLYFISH - Fast, Parallel k-mer Counting for DNA
kmer分析其实是非常耗费计算资源的,如果我们自己写脚本来分析kmer的话,首先要将所有的序列打断成一定长度的kmer,然后将所有的kmer存储起来,最后统计每个kmer出现的频率,或者统计出现指定次 ...
- 2019.01.02 poj3046 Ant Counting(生成函数+dp)
传送门 生成函数基础题. 题意:给出nnn个数以及它们的数量,求从所有数中选出i∣i∈[L,R]i|i\in[L,R]i∣i∈[L,R]个数来可能组成的集合的数量. 直接构造生成函数然后乘起来f(x) ...
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- 【leetcode】Repeated DNA Sequences(middle)★
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- LeetCode() Repeated DNA Sequences 看的非常的过瘾!
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- lc面试准备:Repeated DNA Sequences
1 题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...
- Leetcode:Repeated DNA Sequences详细题解
题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: " ...
- 【LeetCode】Repeated DNA Sequences 解题报告
[题目] All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...
随机推荐
- STL sort
STL的sort()算法,数据量大时采用Quick Sort,分段递归排序,一旦分段后的数据量小于某个门槛,为避免Quick Sort的递归调用带来过大的额外负荷,就改用Insertion Sort. ...
- PyQt 5的基本功能
PyQt5常用的模块 PyQt5的类别分为几个模块,包括: QtCore:包含非核心的GUI功能,此模块用于处理时间.文件和目录.各种数据类型.流.URL.MIME类型.线程或进程 QtGui:包括窗 ...
- linux编辑器使用记录
超强大vim配置文件: wget http://files.cnblogs.com/ma6174/vimrc.zip unzip -f vimrc.zip -d ~/ 一.vim编辑器 进入 ...
- 装linux双系统
一般的电脑都是一个盘的,只要分个区给linux就行了,好装.大概可以看看这篇:http://jingyan.baidu.com/article/c275f6bacc3326e33c756743.htm ...
- datagridview绑定xml
//加载描述的XML private bool loadXML() { //创建DataTable对象dt DataTable dt = new DataTable("clientXML&q ...
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
转自goldeneyezhang原文 C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值 C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值总结: 对应某个类的 ...
- Maven中dependencyManagement使用
在Maven中dependencyManagement的作用其实相当于一个对所依赖jar包进行版本管理的管理器. 在dependencyManagement下申明的dependencies,Maven ...
- 跟着太白老师学python day11 函数名的应用 globals(), locals()
1. 函数名就是内存地址 def func(): ') print(func) >>>> <function func at 0x00000000003DC1E0> ...
- Abstract(抽象)
谈到抽象,就先谈谈面向对象语言的三大特性,也是人们口中常说的封装.继承.多态. 封装:什么是封装,按到我的理解,封装就是把某些类的相关属性和方法封装,对内实现数据影城,对外提供稳定接口. 继承:从字面 ...
- JAVA压缩 解压缩zip 并解决linux下中文乱码
1. [代码][Java]代码 1:再压缩前,要设置linux模式, 需要使用第三方ant-1.6.5.jar 如果是文件目录,则ZipEntry zipEntry=new ZipEntry(b ...