小编gho*_*gho的帖子

价值差异的功能

Python中是否有一个函数来获取列表中两个或多个值之间的差异?那么,在这两个列表中:

list1 = [1, 5, 3, 7]
list2 = [4, 2, 6, 4]
Run Code Online (Sandbox Code Playgroud)

我需要计算list1和list2中每个值之间的差异.

for i in list1:
    for ii in list2:
       print i -ii
Run Code Online (Sandbox Code Playgroud)

这给出了负值,但我希望两个列表的值之间的减法仅从最高值到最低值,以便不获得负值.

对于上面的列表,我希望输出为[3, 3, 3, 3].

谢谢.

python list python-2.7 python-3.x

5
推荐指数
3
解决办法
149
查看次数

将列表删除为字符串

如果代码的输出采用格式

output = [['good'], ['man']]
Run Code Online (Sandbox Code Playgroud)

我只需要'好人',所以我这样做

str(output).strip('],'[')
Run Code Online (Sandbox Code Playgroud)

但它给了

good'], ['man
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

python string list

-1
推荐指数
1
解决办法
45
查看次数

标签 统计

list ×2

python ×2

python-2.7 ×1

python-3.x ×1

string ×1