Determining whether there is a sub-list list python

>>> a=[1,2,3,4,[876,86,435]]
>>> a
[1, 2, 3, 4, [876, 86, 435]]
>>> for i in a:
...  if i>0:
...     print(i)
... 
1
2
3
4
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: unorderable types: list() > int()
>>> type(a[4])
<class 'list'>
>>> for i in a[4]:
...  print(i)
... 
876
86
435
>>> type(a[2])
<class 'int'>
>>> for i in a:
...   if type(i)==list:
...        print(i)
... 
[876, 86, 435]

 

Guess you like

Origin blog.csdn.net/weixin_42528089/article/details/91045611