Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.060 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.01; 'reply- to:addr:comp.lang.python': 0.09; 'subject:string': 0.09; 'to:addr:comp.lang.python': 0.09; 'def': 0.13; 'cc:addr:python- list': 0.15; 'concise.': 0.16; 'rainer': 0.16; 'subject:variable': 0.16; '>>>': 0.18; 'cc:no real name:2**0': 0.21; 'subject:list': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.25; 'cc:addr:python.org': 0.29; 'subject:?': 0.30; 'header:User- Agent:1': 0.33; 'received:209.85.212': 0.34; 'subject:How': 0.35; 'received:google.com': 0.37; 'subject:can': 0.37; 'received:209.85': 0.38; 'received:209': 0.39; 'subject:: ': 0.39; 'more': 0.61; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:googlegroups.com': 0.74; 'subject:content': 0.84; 'received:209.85.212.56': 0.91; 'received :mail-vw0-f56.google.com': 0.91 Newsgroups: comp.lang.python Date: Wed, 1 Feb 2012 23:19:57 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=95.208.115.77; posting-account=F4Pl4woAAAA3GQgXD-VTbzEKduyArjBH References: <1328057052.56088.YahooMailNeo@web30601.mail.mud.yahoo.com> User-Agent: G2/1.0 X-Google-Web-Client: true MIME-Version: 1.0 Subject: Re: How can I verify if the content of a variable is a list or a string? From: Rainer Grimm To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: comp.lang.python@googlegroups.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328167206 news.xs4all.nl 6859 [2001:888:2000:d::a6]:58309 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19772 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