程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python loop structure, how to solve problems with loops

編輯:Python
The phenomenon and background of the problem
# Data processing dataset yes 30 A list of samples a = data.split(',')dataset = [(int(a[i]), int(a[i+1]),int(a[i+2]),int(a[i+3]),int(a[i+4]), int(a[i+5]),......) for i in range(1, len(a)-1, 20)]# Up to int(a[i+44]), I just wrote i+5, It's too much trouble to keep writing , Is there any loop structure that can be implemented ?
Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve



Take the answer :

Double loop write can be used to write in the list parsing formula , Example :

data='100,20,231,351,333,223,13,78,88,98,139,76'.split(',')dataset=[[int(data[i+j]) for j in range(3)]for i in range(0,len(data),3)]print(dataset)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved