Check if all elements of a list are of the same type

前端 未结 9 1851
盖世英雄少女心
盖世英雄少女心 2020-11-28 05:08

How can I check if the elements of a list are of the same type, without checking individually every element if possible?

For example, I would like to have a function

9条回答
  •  天命终不由人
    2020-11-28 05:51

    I prefer to use map for a case like this:

    from types import IntType
    In [21]: map((lambda x: isinstance(x, IntType)), x)
       Out[21]: [True, False, False]
    

提交回复
热议问题