CS50-Python中的DNA分配



我有点拘泥于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

你到底在做什么?要将头加载到一个变量中,可以使用STR = csv_list[0][1:],这样就有了一个模式列表。

然后,您可以使用这个列表变量进行比较(我建议使用正则表达式来更轻松地使用它(。

您可以编写

variable=打开('file_path','r'(

variable=variable.read((

最新更新