| 
 | 
 
 
发表于 2022-10-9 00:01:39
|
显示全部楼层
 
 
 
 
回帖奖励 +10 鱼币
 本帖最后由 jackz007 于 2022-10-9 00:03 编辑  
 
        看看这个代码和结果是否符合要求: 
- def parse_string(term):
 
 -     final_list , i , x , c = [] , 1 , term[0] , 1
 
 -     for i in range(1 , len(term)):
 
 -         if term[i] == x :  
 
 -             c += 1
 
 -         else:
 
 -             final_list . append([str(c) , x])
 
 -             x , c = term[i] , 1
 
 -     final_list . append([str(c) , x])
 
 -     return final_list
 
 - print(parse_string('1211'))
 
 - print(parse_string('1121'))
 
  复制代码 
        运行实况: 
- D:\[00.Exerciese.2022]\Python>python x.py
 
 - [['1', '1'], ['1', '2'], ['2', '1']]
 
 - [['2', '1'], ['1', '2'], ['1', '1']]
 
  
- D:\[00.Exerciese.2022]\Python>
 
  复制代码 |   
 
 
 
 |