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 ...
随机推荐
- sklearn中的predict与predict_proba的区别(得到各条记录每个标签的概率(支持度))
假定在一个k分类问题中,测试集中共有n个样本.则: predict返回的是一个大小为n的一维数组,一维数组中的第i个值为模型预测第i个预测样本的标签: predict_proba返回的是一个n行k列的 ...
- [转]Winform 经验集
多线程篇: CheckForIllegalCrossThreadCalls = false; 更多示例可见: http://www.cnblogs.com/z5337/p/4030287.html i ...
- nginx 作为反向代理实现负载均衡的例子
以下我们就来举例说明如何使用 nginx 实现负载均衡.因为nginx在处理并发方面的优势,现在这个应用非常常见.nginx 这个轻量级.高性能的 web server 主要可以干两件事情: 〉直接作 ...
- canvas之绘制一张图片
<canvas id="canvas" width="600" height="500" style="background ...
- Window下MySql 5.6 安装后内存占用很高的问题
Window下MySql 5.6 安装后内存占用很高的问题 刚刚准备玩一把mysql,初学者 环境是window 7和window sever 2008, mysql是最新的5.6, 发现的问题是安装 ...
- [POJ] Bode Plot
Description Consider the AC circuit below. We will assume that the circuit is in steady-state. Thus, ...
- Python Tuples
1. basic Tuples is a sequence of immutable object. It's a sequence, just like List. However, it cann ...
- 28_java之mysql的CRUD
01数据库概念 * A: 什么是数据库 数据库就是存储数据的仓库,其本质是一个文件系统,数据按照特定的格式将数据存储起来,用户可以对数据库中的数据进行增加,修改,删除及查询操作. * B: 什么是数据 ...
- windows兼容方式安装python[转]
Python 是一门很不错的语言,语言简单易学,又不失脚本语言的灵活性,还有海量的第三方库,覆盖的很全面.但也有不少“硬伤”,比如 Python 2.x 和 Python 3.x 版本之间的不兼容等等 ...
- [js方法pk]之instanceof() vs isPrototypeOf() hasOwnProperty() vs propertyIsEnumerable()
这几个方法在js的高级编程中经常用到,对于新手来说可能还不知道他们有什么区别,我把我的体会总结下来,供大家参考: 首先,定义一个对象: function Parent() {this.name = & ...