基于python中重复值的组阵列值
其值如下,
size=[9, 41, 1368, 887, 307, 9, 114, 81, 9, 34, 12, 13, 12, 4, 548, 3, 77]
以保持恒定值= 9
。
我创建了一个数组
b=41
c=1368,887,307
需要对这些值进行分组,
b=114
c=81
我
b=34
c=12,13,12,4,548,3,77
,
for i in range(0,len(size)):
if size[i-1]!=9:
if(size[0]-size[i])!=0:
print(size[i])
I have created an array whose values are as follows
size=[9, 41, 1368, 887, 307, 9, 114, 81, 9, 34, 12, 13, 12, 4, 548, 3, 77]
I need to group these values keeping a constant value = 9.
Example output required
Group 1
b=41
c=1368,887,307
Group 2
b=114
c=81
Group 3
b=34
c=12,13,12,4,548,3,77
I have no clue how to achieve this, i have tried out following code.
for i in range(0,len(size)):
if size[i-1]!=9:
if(size[0]-size[i])!=0:
print(size[i])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须为这些
9
值扫描输入,并且每次遇到它时,都会启动一个新列表以收集其他值。一旦拥有那些符合人物,您就可以迭代这些并在
b
和c
部分报告:You'll have to scan the input for those
9
values, and each time you encounter it, start a new list for gathering the other values.Once you have those sublists, you can iterate those and report on the
b
andc
parts of those: