博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codewars第二天--Complementary DNA
阅读量:4302 次
发布时间:2019-05-27

本文共 1154 字,大约阅读时间需要 3 分钟。

Codewars第二天–Complementary DNA

开始在Codewars刷Python3题,发现基本知识都忘完了,边刷边复习边记录。

8kyu>>7kyu

Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.If you want to know more http://en.wikipedia.org/wiki/DNAIn DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have function with one side of the DNA (string, except for Haskell); you need to get the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).DNA_strand ("ATTGC") # return "TAACG"DNA_strand ("GTAT") # return "CATA"

这个题目其实很简单,就是执行一个DNA转RNA的过程,给定一个DNA单链字符串,输出与之对应的RNA字符串。

开始自己想得很复杂了,想着弄成列表,结果输出还要转换成字符串。。。

在这里只需要写一个类似switch的判断就好了,然后再用join()把每一个转换好的RNA字符链接成字符串输出就好了。

代码如下:

def DNA_strand(dna):    # code here    my = {            "A" : "T",            "T" : "A",            "C" : "G",            "G" : "C",            }    return "".join(my[i] for i in dna)

代码中my 实现了对输入的DNA字符串进行转换的过程。


join()用法:

用于将序列中的元素以指定的字符链接生成一个新的字符串。也就是使用它之后生成的只能是字符串。

str.join(sequence)

前面的str指的是使用什么字符来连接需要连接的元素序列sequence

这里我们不需要任何字符来连接就默认""

转载地址:http://immws.baihongyu.com/

你可能感兴趣的文章
记一次断电恢复ORA-01033错误
查看>>
C#修改JPG图片EXIF信息中的GPS信息
查看>>
从零开始的Docker ELK+Filebeat 6.4.0日志管理
查看>>
Sequelize的原始查询的时区问题
查看>>
How it works(1) winston3源码阅读(A)
查看>>
How it works(2) autocannon源码阅读(A)
查看>>
How it works(3) Tilestrata源码阅读(A)
查看>>
How it works(12) Tileserver-GL源码阅读(A) 服务的初始化
查看>>
uni-app 全局变量的几种实现方式
查看>>
echarts 为例讲解 uni-app 如何引用 npm 第三方库
查看>>
uni-app跨页面、跨组件通讯
查看>>
springmvc-helloworld(idea)
查看>>
JDK下载(百度网盘)
查看>>
idea用得溜,代码才能码得快
查看>>
一篇掌握python魔法方法详解
查看>>
数据结构和算法5-非线性-树
查看>>
数据结构和算法6-非线性-图
查看>>
数据结构和算法7-搜索
查看>>
数据结构和算法8-排序
查看>>
windows缺少dll解决办法
查看>>