0

how to determine where is list where is not?

25th Sep 2016, 8:48 AM
tan nguyen
tan nguyen - avatar
7 Respostas
+ 2
You should try with isinstance(variable, list). I am not really sure what type is a list, but I think it's that one. But you could always override the "magic method" for isinstance to give the function the behaviour you want
25th Sep 2016, 11:44 AM
Amaras A
Amaras A - avatar
+ 1
Refine your thought, please. I don't understand what you mean
25th Sep 2016, 11:14 AM
Amaras A
Amaras A - avatar
+ 1
I mean are there some attribute or function that can be let we know it's a list or not
25th Sep 2016, 11:37 AM
tan nguyen
tan nguyen - avatar
+ 1
no : a string also has the square brackets
25th Sep 2016, 12:45 PM
Amaras A
Amaras A - avatar
+ 1
I totally agree with Amaras A. simply check, if isinstance(e,list): if you want to find if it is a list or tuple you can add tuple if isinstance(e,(list,tuple))
26th Sep 2016, 6:32 AM
Rana Sarkar
Rana Sarkar - avatar
0
actually your question is good...we can find list by the square bracket [ ]
25th Sep 2016, 12:34 PM
Gurtej Singh
Gurtej Singh - avatar
0
you can use print type(variable_name)
25th Sep 2016, 5:21 PM
Hardi