在我的表格中,我有不同类型的日期,只是数字和这两种格式:
yyyy-m-d
yyyy-mm-dd
Run Code Online (Sandbox Code Playgroud)
某些值(例如月份)在小于10的月份中不为零,我需要它来创建条件以在最新日期之前选择元素。
我希望它们都具有相同的格式:
yyyy-mm-dd
Run Code Online (Sandbox Code Playgroud)
任何pythonic的方式来解决这个问题?
目前,我正在使用此:
if line.startswith('# Date: '):
#date = 2014-5-28
d = line.strip().split(':')[-1].split('-').replace(' ','')
if len(d[0]) == 4:
year = str(d[0])
elif len(d[1]) < 2:
month = '0'+ str(d[1])
elif len(d[2]< 2):
day = '0'+ str(d[1])
date = year + month + day
Run Code Online (Sandbox Code Playgroud) 在简历中,我在同一个字典中有两个键,每个键都有对应的列表。
我尝试比较两个列表以检查公共元素和差异元素。这意味着输出 I 将计算有多少元素相同或仅出现在一个键的列表中。
从一开始我就使用文件作为参数插入元素,并在函数中读取它们
def shared(list):
dict_shared = {}
for i in list:
infile = open(i, 'r')
if i not in dict_shared:
dict_shared[i] = []
for line in infile:
dict_shared[spacer].append(record.id)
return dict_shared
Run Code Online (Sandbox Code Playgroud)
现在我被困在试图找到一种方法来比较字典中创建和显示的列表。
dict = {a:[1,2,3,4,5], b:[2,3,4,6]}
Run Code Online (Sandbox Code Playgroud)
我的目的是比较列表,以便在两个文本之间共享行。
a: [1,5]
b: [6]
a-b: [2,3,4]
Run Code Online (Sandbox Code Playgroud)
从现在开始我找不到解决这个问题的方法。有什么建议吗?
我有一本字典,每个键的值长度不同。试图以a表示boxplot,我无法前进。还有其他方法吗?
我写了这个,但是不起作用:
import matplotlib.pyplot as plt
import matplotlib as mpl
dict1 = {'Pb': [53.0, 56.0, 56.0, 57.0, 57.0, 57.0, 46.0], 'Pa': [56.0, 55.0], 'Pg': [57.0, 57.0, 58.0, 57.0, 57.0, 57.0, 57.0, 57.0,53.0, 57.0, 55.0, 58.0, 58.0, 58.0, 57.0, 57.0, 57.0, 57.0, 57.0, 55.0, 55.0, 57.0, 57.0, 55.0, 58.0, 58.0, 58.0, 55.0, 58.0, 54.0, 58.0, 57.0, 57.0, 58.0, 55.0, 56.0, 55.0, 55.0, 55.0, 58.0, 56.0, 57.0, 57.0, 57.0, 57.0, 56.0, 57.0, 56.0],'Pf': [54.0], 'Pn': [56.0, 56.0, 55.0, 56.0, 56.0, …Run Code Online (Sandbox Code Playgroud) 考虑这个清单:
l1 = ['Bio:PRJNA57967', 'Assembly:GCF_000007805.1']
l2 = ['Bio:PRJNA224116', 'Sample:SAMN07158965', 'Assembly:GCF_002318635.1']
Run Code Online (Sandbox Code Playgroud)
如果不考虑'Assembly'总是在最后一个位置,我想要检索这个值.
而不是选择最后一个元素l [-1],我需要一些建议,如果它出现在列表的另一个位置,我可以找到'汇编'.
我的命令包括以下行:
for i in l:
if i.contains('Assembly'):
print i
Run Code Online (Sandbox Code Playgroud)
要跳过循环,是否可以使用循环来定义我的变量来搜索我想要使用的元素?像这样:
name = ( i for i in dbxrefs and i.startswith('Assembly:'))
Run Code Online (Sandbox Code Playgroud)