小编smi*_*y23的帖子

Python 3 - 将列表中的数字乘以2

我要求完成的代码的目的是接收给定库存的输入,将它们返回到一行中的列表中.然后在第二行,复制列表,但这次加倍数字.

给定的输入是

Choc 5; Vani 10; Stra 7; Choc 3; Stra 4
Run Code Online (Sandbox Code Playgroud)

所需的输出是:

[['Choc', 5], ['Vani', 10], ['Stra', 7], ['Choc', 3], ['Stra', 4]]
[['Choc', 10], ['Vani', 20], ['Stra', 14], ['Choc', 6], ['Stra, 8]]
Run Code Online (Sandbox Code Playgroud)

我已经成功地获得了第一线的所需输出,但我正在努力争取如何成功地竞争第二线.

这是代码:

def process_input(lst):
    result = []
    for string in lines:
        res = string.split()
        result.append([res[0], int(res[1])])
    return result

def duplicate_inventory(invent):
    # your code here
    return = []
    return result

# DON’T modify the code below
string = input()
lines = []
while string != "END":
    lines.append(string)
    string …
Run Code Online (Sandbox Code Playgroud)

python list python-3.x

4
推荐指数
1
解决办法
100
查看次数

标签 统计

list ×1

python ×1

python-3.x ×1