小编lui*_*ini的帖子

如何将多行语句写入单行python字典

我想在一行代码下面编写此代码。我有很多数据。因此页面继续。所以我想缩小它。如何使其成为可能。我知道在python中是可能的。为我提供一些解决方案。

data['url']=url
data['user agent']=userAgent
data['browser']=browser
data['uniqueId']=uniqueId
data['ip']=ip
data['language']=language
and its going on.
Run Code Online (Sandbox Code Playgroud)

我试过了,但是失败了。

data['url','user agent','browser'...] = url,useragent,browser....
Run Code Online (Sandbox Code Playgroud)

python dictionary python-3.x

3
推荐指数
1
解决办法
59
查看次数

返回列表,其中元素从turn / python中的列表中获取

我需要帮助将2个列表转换为元素从两个列表中依次提取的位置

def combine_lists(a, b):
    """
    combine_lists([1, 2, 3], [4]) => [1, 4, 2, 3]
    combine_lists([1], [4, 5, 6]) => [1, 4, 5, 6]
    combine_lists([], [4, 5, 6]) => [4, 5, 6]
    combine_lists([1, 2], [4, 5, 6]) => [1, 4, 2, 5, 6]
    :param a: First list
    :param b: Second list
    :return: Combined list
    """
Run Code Online (Sandbox Code Playgroud)

我试过的

# return a[0], b[0], a[1], b[1]
    combined_list = []
    for x, y in range (len(a), len(b)):
        combined_list = a[x], b[y]
    return combined_list
Run Code Online (Sandbox Code Playgroud)

python loops list python-3.x

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

标签 统计

python ×2

python-3.x ×2

dictionary ×1

list ×1

loops ×1