首页 > 编程语言 >一道经典的python题目【多测师_王sir】

一道经典的python题目【多测师_王sir】

时间:2022-10-26 13:01:45浏览次数:41  
标签:sir 多测师 python list num result value1 new append

#coding=utf-8
"""
===========================
Author:多测师_王sir
Time:2020-11-22 14:50
===========================
"""

'''
题目:
python的列表里相邻一样的元素组成一个列表,[1,1,3,6,6,7,7,7,8,5,5,5]
最后要变成[[1,1],[3],[6,6],[7,7,7],[8],[5,5,5]]
'''
def duoceshi(num_list):
result_list =[]
for i in range(0,len(num_list)):
new_list = []
if num_list:
value1 = num_list.pop(0)
new_list.append(value1)
for j in range(0,len(num_list)):
if num_list[0] == value1:
value2 =num_list.pop(0)
new_list.append(value2)
result_list.append(new_list)
print(result_list)
duoceshi([1, 1, 3, 6, 6, 7, 7, 7, 8, 5, 5, 5])

 



标签:sir,多测师,python,list,num,result,value1,new,append
From: https://blog.51cto.com/u_15846941/5797823

相关文章