社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  XxJames07-  »  全部回复
回复总数  3
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