私信  •  关注

dsenese

dsenese 最近创建的主题
dsenese 最近回复了
3 年前
回复了 dsenese 创建的主题 » 如果两个元素相邻,则在Python中拆分列表

下面是一个简单的工作代码:

test = [3,5,7,1,10,17]

def neighbor_splitting():
    for x in test:
        if x == 10:
            index = test.index(x)
            list1 = test[:index]
            list2 = test[index:]
            return list1, list2

# [3, 5, 7, 1]
# [10, 17]