私信  •  关注

XxJames07-

XxJames07- 最近创建的主题
XxJames07- 最近回复了
3 年前
回复了 XxJames07- 创建的主题 » 在python列表中只创建相同的对

你可以这样做:

list = [1,2,3,4,5,6,7]
def chunks(lst, n):
    """Yield successive n-sized chunks from lst."""
    for i in range(0, len(lst), n):yield lst[i:i + n]    
sublist = [x for x in chunks(list, 2)]
for x in sublist:
    if x.__len__() > 1:continue
    else:sublist.remove(x)
print(sublist)

输出:

[[1,2],[3,4],[5,6]]

3 年前
回复了 XxJames07- 创建的主题 » python_数据['division']中的语法无效。追加(int(拆分[3]))

括号不是闭合的

data["age"].append(int(split[2]) <- here

而是写:

data["age"].append(int(split[2]))
3 年前
回复了 XxJames07- 创建的主题 » 如何在Python中循环多变量数据

你可以这样做:

cities = ["Rome", "NYC"]
latitude = [41.2925, 40.730610]
longitude = [12.5736, 73.935242]
for (a, b, c) in zip(longitude, latitude, cities): #zips the lists together
     print ("long = %s, lat= %s, city:%s" % (a, b, c)) 

输出:

long = 12.5736, lat= 41.2925, city:Rome
long = 73.935242, lat= 40.73061, city:NYC