小编Fel*_*ixF的帖子

如何交错两个不同长度的列表?

我是Python的新手,我仍然很难将语言本身用于我的程序.这是我到目前为止所拥有的:

# Purpose: 'twolists' = takes 2 lists, & returns a new list containing
# alternating elements of lists. 
# Return = final_list
# Parameter = list1, list2

def twolists(list1, list2): # don't forget to return final_list
    alt_list = []
    a1 = len(list1)
    a2 = len(list2)

    for i in range(# ? ):
        # append one thing from list1 to alt_list - How?
        # append one thing from list2 to alt_list - How?
Run Code Online (Sandbox Code Playgroud)

现在该程序应该产生如下输出:

outcome = twolists([ ], ['w', 'x', 'y', …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
2
解决办法
1695
查看次数

标签 统计

python ×1