Test type of elements python tuple/list

前端 未结 4 1581

How do you verify that the type of all elements in a list or a tuple are the same and of a certain type?

for example:

(1, 2, 3)  # test for all int          


        
4条回答
  •  情歌与酒
    2020-12-05 05:15

    Only to mention the possibility, you can avoid list comprehension with:

    all(map(lambda x: isinstance(x, int), your_list))
    

提交回复
热议问题