简体   繁体   English

CS50 - Python 中的 DNA 分配

[英]CS50 - DNA Assignment in Python

I'm kinda stuck on DNA cs50's pset, how can I load the text into a variable, get the headers from the first row and start counting this is my code so far:我有点卡在 DNA cs50 的 pset 上,如何将文本加载到变量中,从第一行获取标题并开始计算这是我到目前为止的代码:

with open(sys.argv[1]) as csvfile:
    csv_reader = csv.reader(csvfile)
    csv_list = list(csv_reader)

STR = 
for STR in csv_list[0][1:]:
    if 'AGAT' in csv_list[STR]:
        count += 1

What exactly are you stuck on?你到底在坚持什么? To load the headers into a variable, you can use STR = csv_list[0][1:] so that you have a list of the patterns.要将标题加载到变量中,您可以使用STR = csv_list[0][1:]以便您拥有模式列表。

You can then use this list variable to do your comparisons (I recommend using regular expressions to just get more comfortable with it).然后你可以使用这个列表变量来进行比较(我建议使用正则表达式来让它更舒服)。

You can write你可以写

variable = open('file_path', 'r')变量 = open('file_path', 'r')

variable = variable.read()变量 = 变量.read()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM