On Wed, 01 Feb 2012 23:19:57 -0800, Rainer Grimm wrote:
> You can do it more concise.
>
def isListOrString(p):
> ...return any((isinstance(p,list),isinstance(p,str)))
Or even more concisely still:
isinstance(p, (list, str))
--
Steven
--
http://mail.python.org/mailman/listinfo/pyt
You can do it more concise.
>>> def isListOrString(p):
...return any((isinstance(p,list),isinstance(p,str)))
...
>>> listOrString("string")
True
>>> listOrString([1,2,3])
True
>>> listOrString(2)
False
>>> listOrString(False)
False
Rainer
--
http://mail.python.org/mailman/listinfo/python-lis
On Wed, Feb 1, 2012 at 12:11 PM, Andres Soto wrote:
>
> okok, my mistake is that I was using string in place of str. Thank you!!
> regards
Tip: In the interactive interpreter, enter:
>>> type("spam")
In Python 2, it'll say "type" not "class", but same diff. It tells you
there what the type is.
M
>Subject: Re: How can I verify if the content of a variable is a list or a
>string?
>
>On Wed, Feb 1, 2012 at 12:44 AM, Andres Soto wrote:
>> Hi,
>> I'm writing a function which receive a list which elements are strings or
>> new lists (sublists) containing str
On Wed, Feb 1, 2012 at 12:44 AM, Andres Soto wrote:
> Hi,
> I'm writing a function which receive a list which elements are strings or
> new lists (sublists) containing strings.
> How can I verify if sone element of the list (which is contained in a
> variable) is a list or a string?
> I found the
On 1/31/2012 7:44 PM, Andres Soto wrote:
Hi,
I'm writing a function which receive a list which elements are strings
or new lists (sublists) containing strings.
How can I verify if sone element of the list (which is contained in a
variable) is a list or a string?
I found the method isinstance(obje
Hi,
I'm writing a function which receive a list which elements are strings or new
lists (sublists) containing strings.
How can I verify if sone element of the list (which is contained in a variable)
is a list or a string?
I found the method isinstance(object,class) but I don't know which class