Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104886
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Use of Lists, Tupples, or Sets in IF statement. |
| Date | Tue, 15 Mar 2016 11:33:07 +1100 |
| Lines | 35 |
| Message-ID | <mailman.142.1458001996.12893.python-list@python.org> (permalink) |
| References | <fcd34352-44d2-4912-b76c-7b3860c4fe1e@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de g5Si1FOEAqyOpXmMK9P1ogW10uceATvZfK4lFWAdQSzA== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'matches': 0.07; 'cc:addr:python-list': 0.09; 'spelled': 0.09; 'python': 0.10; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'fruit.': 0.16; 'operator.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'element': 0.18; 'variable': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; '15,': 0.30; 'e.g.': 0.30; 'tue,': 0.34; 'received:google.com': 0.35; 'set.': 0.35; 'list,': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'mar': 0.65; 'chrisa': 0.84; 'subject:Sets': 0.84; 'to:none': 0.91; 'subject:Lists': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=htQ+xikFhoFlv5RS8XzfPvErfrNjkih1TYeUy82dBdQ=; b=EqNzVv/0TI9H8dJKkRcl7Esu8aJB/9UO2EXtVSmB4a4ZrSmChDV1TNEpJ9f/krv1dj 0bbP01wfR/gcrSNKOeBKhLbvA/Y5eYu53aYV2i+gClm0yTfggJcsC1IUXPeT4RGMyZuc Z8SyFZ2exykNOIZHabEVNblYrHpR7HSK11goCdXGh+SQZjhsD8eSr96/ColvQtdDc04W U+Hu1ns1NTk6zX6AAztPUGoUnMxMPIxdt0QRBI7WyCvLNPVEAWjuA935kuU81VQASJdc 1zpgLJ6n83UtX0OCfUpdT5f3mJuO1VDnf7sQeKNJ4pGTkem0kBy9WMN1oOVKSV//iZs8 lfMQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=htQ+xikFhoFlv5RS8XzfPvErfrNjkih1TYeUy82dBdQ=; b=Y+iQkzN5iQ68GP5Z4fCdOg4FCGlyfSGwqZWP8Yu/KcUykofZk9QtMorEA4nyFI+vN5 nAMBIjD322hE82Xdl1ruQJFdYuRtEuR9ZVlkAUb21bBc7OqXPXtMXthC7AUI/lhj7fff yZDRGsqhGpnYibIG22IMAC6znW34D5FSrAiRon0lw1rrNyESyazfBMWEaiILUd8Afszv oJUd8dR6ajKS0aer0xGB681NTSjHSFffnu67UgM3RgyjR1PW4GA6Sl6nhdYHIiZ6fomF WdHDryTwv2xiHYn1u+Ge+3kNgVSwnvc9c43murF5w3yGVRRJ4WXgvsrsAPSlG3Jq6dDE OtVg== |
| X-Gm-Message-State | AD7BkJKio+ujHHLgXIG/N6dqR5UbMh/jPeh9fSMkth8OBj05eTrG9n+weXGtpZD3SeaA7q+MBGlgpU/v/dJOkw== |
| X-Received | by 10.50.43.168 with SMTP id x8mr20996106igl.92.1458001987789; Mon, 14 Mar 2016 17:33:07 -0700 (PDT) |
| In-Reply-To | <fcd34352-44d2-4912-b76c-7b3860c4fe1e@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:104886 |
Show key headers only | View raw
On Tue, Mar 15, 2016 at 11:26 AM, <jj0gen0info@gmail.com> wrote:
> In Python is it possible to comparison-equate a variable to a List, Tupple, or Set and have it return True if the contents of the variable matches an element in the List, Tupple, or Set.
>
> E.g.
>
> x = "apple"
>
> x-list = ["apple", "banana", "peach"]
>
> If x == x-list:
> print('Comparison is True')
> else:
> print('Comparison is False')
Yep! What you're looking for is the "membership" operator. It's spelled "in":
>>> x = "apple"
>>> x_list = ["apple", "banana", "peach"]
>>>
>>> if x in x_list:
... print("That is a fruit.")
... else:
... print("That is not a fruit.")
...
That is a fruit.
>>> x = "jump"
>>> if x in x_list:
... print("That is a fruit.")
... else:
... print("You must be Chell.")
...
You must be Chell.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Use of Lists, Tupples, or Sets in IF statement. jj0gen0info@gmail.com - 2016-03-14 17:26 -0700
Re: Use of Lists, Tupples, or Sets in IF statement. Joel Goldstick <joel.goldstick@gmail.com> - 2016-03-14 20:31 -0400
Re: Use of Lists, Tupples, or Sets in IF statement. Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:33 +1100
Re: Use of Lists, Tupples, or Sets in IF statement. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 00:38 +0000
Re: Use of Lists, Tupples, or Sets in IF statement. jj0gen0info@gmail.com - 2016-03-14 18:32 -0700
Re: Use of Lists, Tupples, or Sets in IF statement. jj0gen0info@gmail.com - 2016-03-14 18:24 -0700
Re: Use of Lists, Tupples, or Sets in IF statement. Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:10 +1100
Re: Use of Lists, Tupples, or Sets in IF statement. Rustom Mody <rustompmody@gmail.com> - 2016-03-14 23:30 -0700
Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Peter Otten <__peter__@web.de> - 2016-03-15 09:29 +0100
Re: Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Rustom Mody <rustompmody@gmail.com> - 2016-03-15 04:08 -0700
Re: Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Peter Otten <__peter__@web.de> - 2016-03-15 18:34 +0100
Re: Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Rustom Mody <rustompmody@gmail.com> - 2016-03-15 19:54 -0700
csiph-web