我有一个包含键和值数据的数据列表,但有时它只包含数据。我想跳过这类数据。你知道吗
我得到了下面的答案错误:-你知道吗
示例:-
formatted_desc_split = ['Akshay Godase is from pune', 'Amar:Satara', 'Sandesh:Solapur', 'Mahesh:Nagpur', 'Prashant:Indapur']
for each_split_data in formatted_desc_split:
split_by_colon = each_split_data.split(":")
Error :-
IndexError: list index out of range
我想跳过Akshay Godase is from pune
数据。若列表中并没有键和值对,那个么我想跳过这个数据。我无法拆分此数据,因为在第一个索引中没有键值paire。你知道吗
如何解决上述问题?你知道吗
使用列表理解。简洁、易读、易懂:
请改为使用以下命令:
可能不是一种优雅的方式,但是下面的代码实现了您想要的。只是为了另一个解决方案。你知道吗
相关问题 更多 >
编程相关推荐