[英]How to check in Python for each element of a list, whether it is contained in another list?
[英]How to make each element in a list another list in python
我有一個循環內的列表,例如
A=[25,45,34,....87]
在下一次迭代中,A應該是
A=[[25,32],[45,13],[34,65],....[87,54]]
在下一次迭代中,A應該是
A=[[25,32,44],[45,13,67],[34,65,89],....[87,54,42]]
等等,我該怎么辦?可能嗎?我正在處理的代碼是
s=0
e=25
for i in range(0,4800):
if not m_list_l:
m_list_l.append(max(gray_sum[s:e]))
m_list_l[i].append(max(gray_sum[s:e]))
s+=25
e+=25
但這給我錯誤
m_list_l[i].append(max(gray_sum[s:e]))
AttributeError: 'int' object has no attribute 'append'
您插入的第一個元素應該是列表,而不是int。 將m_list_l.append(max(gray_sum[s:e]))
更改為m_list_l.append([max(gray_sum[s:e])])
此問題。
說有兩個列表,
A = [i for i in range(10,100,10)]
A
[10, 20, 30, 40, 50, 60, 70, 80, 90]
B = [i for i in range(20,100,10)]
B
[20, 30, 40, 50, 60, 70, 80, 90, 100]
合並列表將是
L = [[i,j] for i,j in zip(A,B)]
L
[[10, 20],
[20, 30],
[30, 40],
[40, 50],
[50, 60],
[60, 70],
[70, 80],
[80, 90],
[90, 100]]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.