我想在python(而不是任何其他函数)中使用join函数将两个列表合并到嵌套列表中,假设列表长度相等,例如:
list1 = [1, 2, 3]
list2 = ["a", "b", "c"]
Run Code Online (Sandbox Code Playgroud)
我希望它生成一个这样的新列表:
[[1,"a"], [2,"b"], [3,"c"]]
Run Code Online (Sandbox Code Playgroud) 我有这样的文本文件:
771 776 #1 556.766700(2)
538 #2 1069.652700(2)
531 #3 1074.407600(2)
81 84 89 94 111 #4 1501.062900(2)
85 91 #5 782.298900(3)
32 42 66 71 90 95 101 #6 904.016500(3)
Run Code Online (Sandbox Code Playgroud)
我想分割并将子串保存到不同的变量,如下所示:例如在第1行:
scans= 771 776, uid = 1 mz = 556.766700, z = 2
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下代码,但我需要有关正则表达式的帮助:
f = open(filename, 'r')
par_info=[]
for rows in f:
re.sub('\#(.+)\s(.+)\((.+)\+', scans=\g<1>, uid=\g<2>, mz = int(\g<3>), z=int(\g<4>), rest)
info={'sc_num':scans, 'ident':uid, 'mass':mz, 'charge':z}
par_info.append(info)
Run Code Online (Sandbox Code Playgroud) 当我建立:
import matplotlib
pyplot.plot([1,2,3,4])
pyplot.ylabel('some numbers')
pyplot.show()
Run Code Online (Sandbox Code Playgroud)
我明白了:
Traceback (most recent call last):
File "/Users/Paulair/Desktop/mathGraphing.py", line 2, in <module>
pyplot.plot([1,2,3,4])
NameError: name 'pyplot' is not defined
[Finished in 0.2s with exit code 1]
Run Code Online (Sandbox Code Playgroud)
当我建立:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
Run Code Online (Sandbox Code Playgroud)
有用.
def __str__(self):
summa = 0
for a in self.__pisteet:
summa += a
mjono += str(a)
return "{:s} {:s} yhteensa", summa, "pistetta".format(self.__nimi, mjono)
Run Code Online (Sandbox Code Playgroud)
所以有多个玩家,我应该能够打印他们的所有名字,所有分数和分数总和.
TypeError: __str__ returned non-string (type tuple)
Run Code Online (Sandbox Code Playgroud) def check(temp):
for i in temp:
if type(i) == str:
temp.remove(i)
temp = ['a', 'b']
print(temp) ==> Output: ['a','b']
check(temp)
print(temp) ==> Output: ['b']
Run Code Online (Sandbox Code Playgroud)
在运行时
temp = ['a',1],输出为[1]
temp = [1,'a','b','c',2],输出为[1,'b',2]
有人可以解释如何评估结果.. Thnx
我有这样的清单
['a', 'pnp', 'a|pnp', 'lab2|pnp']
Run Code Online (Sandbox Code Playgroud)
我想分开它们并拥有它
['a', 'pnp', 'a', '|', 'pnp', 'lab2', '|', 'pnp']
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
给出一个数据列表:
[[0, 0], [1, 0], [0, 1], [-1, 0], [0, -1], [1, -1], [2, 0], [1, 1], [0, 2]]
Run Code Online (Sandbox Code Playgroud)
在python中获得最低X和Y的最快方法是什么.在这种情况下[-1,-1].
我有一个字符串列表,前缀字符代表数字的倍增因子.所以如果我有这样的数据:
data = ['101n', '100m', '100.100f']
Run Code Online (Sandbox Code Playgroud)
我想用字典
prefix_dict = {'y': 'e-24', 'z': 'e-21', 'a': 'e-18', 'f': 'e-15', 'p': 'e-12',
'n': 'e-9', 'u': 'e-6', 'm': 'e-3', 'c': 'e-2', 'd': 'e-1',
'da': 'e1', 'h': 'e2', 'k': 'e3', 'M': 'e6', 'G': 'e9',
'T': 'e12', 'P': 'e15', 'E': 'e18', 'Z': 'e21', 'Y': 'e24'}
Run Code Online (Sandbox Code Playgroud)
插入相应的字符串.当我看到与我类似的其他问题时,有一个角色被翻译成另一个角色.有没有办法使用translate函数将一个字符翻译成多个字符,还是应该以不同的方式接近它?
我一直试图减去(并组合乘法等)两个Numpy数组,以便生成的数组只有在这些地方留下的值,而另一个数组没有数据.
就像我有矩阵a和b一样,ab会给c:
a = np.array([0,2,3,0])
b = np.array([1,0,3,0])
c = np.array([0,2,0,0])
Run Code Online (Sandbox Code Playgroud)
我已经尝试将b乘以一个非常大的数字,但后来我无法弄清楚如何摆脱负值.还有一个数组a和b的缺失值为-999.
非常感谢帮助!谢谢!
假设我有一个矩阵,如:
4 0 3 5
0 2 6 0
7 0 1 0
Run Code Online (Sandbox Code Playgroud)
我希望它二进制化为:
0 0 0 0
0 1 0 0
0 0 1 0
Run Code Online (Sandbox Code Playgroud)
即将阈值设置为2,将大于阈值的任何元素设置为0,将小于或等于阈值的任何元素(除0)设置为1.
我们可以在python的csr_matrix或任何其他稀疏矩阵上执行此操作吗?
我知道scikit-learn提供Binarizer将低于或等于阈值的值替换为0,高于1.
python ×10
list ×5
string ×3
dictionary ×2
numpy ×2
arrays ×1
matrix ×1
performance ×1
python-3.x ×1
regex ×1