简体   繁体   English

遍历嵌套列表到 append 仅整数

[英]Iterating through a nested list to append only integers

How can I iterate through this list to then store only the first numbers in each element of the list?我怎样才能遍历这个列表,然后只存储列表的每个元素中的第一个数字? So for the first element in the list I would want to basically have maybe a list which would be lst = [199] and then for the second element it would be lst = [199, 196] and then for the third, lst = [199, 196, 203].因此,对于列表中的第一个元素,我基本上希望有一个列表,它可能是 lst = [199],然后对于第二个元素,它将是 lst = [199, 196],然后对于第三个元素, lst = [ 199、196、203]。

['Ball Apple 199 4', 'Banana Car 196 7 ', 'Cherry Grape 203 8']

How can I iterate through this list to then store only the first numbers in each element of the list?我怎样才能遍历这个列表,然后只存储列表的每个元素中的第一个数字? So for the first element in the list I would want to basically have maybe a list which would be lst = [199] and then for the second element it would be lst = [199, 196] and then for the third, lst = [199, 196, 203].因此,对于列表中的第一个元素,我基本上希望有一个列表,它可能是 lst = [199],然后对于第二个元素,它将是 lst = [199, 196],然后对于第三个元素, lst = [ 199、196、203]。

['Ball Apple 199 4', 'Banana Car 196 7 ', 'Cherry Grape 203 8']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM