Problem

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. 1.Counting DNA Nucleotides

    Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...

  2. JELLYFISH - Fast, Parallel k-mer Counting for DNA

    kmer分析其实是非常耗费计算资源的,如果我们自己写脚本来分析kmer的话,首先要将所有的序列打断成一定长度的kmer,然后将所有的kmer存储起来,最后统计每个kmer出现的频率,或者统计出现指定次 ...

  3. 2019.01.02 poj3046 Ant Counting(生成函数+dp)

    传送门 生成函数基础题. 题意:给出nnn个数以及它们的数量,求从所有数中选出i∣i∈[L,R]i|i\in[L,R]i∣i∈[L,R]个数来可能组成的集合的数量. 直接构造生成函数然后乘起来f(x) ...

  4. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  5. 【leetcode】Repeated DNA Sequences(middle)★

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  6. LeetCode() Repeated DNA Sequences 看的非常的过瘾!

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  7. lc面试准备:Repeated DNA Sequences

    1 题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...

  8. Leetcode:Repeated DNA Sequences详细题解

    题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: " ...

  9. 【LeetCode】Repeated DNA Sequences 解题报告

    [题目] All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...

随机推荐

  1. Linux:WebServer(Apacge)

    / + 内容:表示在文本中搜索该内容: :q!:不保存直接退出: chown  -R  imooc:imooc /data:将 /data 文件夹的权限所有人该为用户 imooc: -R:采用递归的方 ...

  2. 【转】JMeter-Java Sampler编写范例

    今天,听段念的培训,学了一下Jmeter写Java请求的过程. 根据某博文,修改其中代码的bug后,贴在下面吧:另外公司一同学Raylupas在半年前也写过关于JMeter写Java Sampler的 ...

  3. python算两个时间之间的天数,将天数转成int型

    import time import datetime #计算两个日期相差天数,自定义函数名,和两个日期的变量名. def Caltime(date1,date2): #%Y-%m-%d为日期格式,其 ...

  4. Java-Runoob:Java 正则表达式

    ylbtech-Java-Runoob:Java 正则表达式 1.返回顶部 1. Java 正则表达式 正则表达式定义了字符串的模式. 正则表达式可以用来搜索.编辑或处理文本. 正则表达式并不仅限于某 ...

  5. 缓存varnish的管理及配置详解

    一 工作原理 在当前主流的Web服务架构体系中,Cache担任着越来越重要的作用.常见的基于浏览器的C/S架构,Web Cache更是节约服务器资源的关键.而最近几年由FreeBSD创始人之一Kamp ...

  6. OD 实验(三) - 破解程序的文件验证

    需要破解的程序 双击程序,提示需要许可证文件 逆向程序 用 OD 打开 LoadIconA 为加载图标 LoadCursorA 为加载鼠标 F8 走一下程序 走到了这里,调用了 CreateFileA ...

  7. 初识python(python的安装与运行)

    python--“优雅”.“明确”.“简单”的哲学定位 一.python的安装(Windows环境下) 1.在python官网下载安装文件 python的官方网址:https://www.python ...

  8. python3.5+flask+mysql

    该篇博客配置环境为:python版本3.5,flask2.0,python3中已经不再支持MySQLdb模块,所有这里我用了pymysql,所有使用前应该 安装pymysql:pip install ...

  9. 各自平台token获取解析及用户信息的获取

    1.auth根据手机号码获取auth平台session_token记统一认证的user_id与pass_id [dwliuchao1@GD-QHD-CNG152TFKX-12.55 logs]$ cd ...

  10. Swift 延迟运行代码

    // // DelayRun.swift // // Created by XuQing on 16/7/1. // Copyright © 2016年 xuqing. All rights rese ...