Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56737
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'argument': 0.05; 'subject:code': 0.07; 'lawrence': 0.09; 'planned.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'red,': 0.16; 'slight': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'help.': 0.21; 'print': 0.22; 'header:User-Agent:1': 0.23; "i've": 0.25; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'leave': 0.29; 'wonder': 0.29; "doesn't": 0.30; "i'm": 0.30; 'work.': 0.31; 'gives': 0.31; 'keys': 0.31; 'run': 0.32; "i'd": 0.34; 'basic': 0.35; 'problem.': 0.35; 'but': 0.35; 'version': 0.36; 'thanks': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'too': 0.37; 'apple': 0.38; 'filled': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'does': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'how': 0.40; 'most': 0.60; "you've": 0.63; 'email addr:gmail.com': 0.63; 'name': 0.63; 'refer': 0.63; 'effectively': 0.66; 'due': 0.66; 'subject:this': 0.83; 'fish': 0.84; 'lazy': 0.91; 'subject:want': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: Why isn't this code working how I want it to? |
| Date | Sat, 12 Oct 2013 10:39:48 +0100 |
| References | <f74fadac-e7c3-4419-9a65-ed6ecd5eb3fe@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | host-78-147-178-154.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 |
| In-Reply-To | <f74fadac-e7c3-4419-9a65-ed6ecd5eb3fe@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1033.1381570800.18130.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1381570800 news.xs4all.nl 15936 [2001:888:2000:d::a6]:47784 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:56737 |
Show key headers only | View raw
On 12/10/2013 09:56, reubennottage@gmail.com wrote:
> I've been working on a program and have had to halt it due a slight problem. Here's a basic version of the code:
>
> a = 'filled'
> b = 'filled'
> c = 'empty'
> d = 'empty'
> e = 'filled'
> f = 'empty'
> g = 'filled'
>
> testdict = {a : 'apple' , b : 'banana' , c : 'cake' , d : 'damson' , e : 'eggs' , f : 'fish' , g : 'glue'}
>
> Now what I want to do, is if a variable is filled, print it out. This however isn't working how I planned. The following doesn't work.
>
> for fillempt in testdict:
> if fillempt == 'filled':
> print(testdict[fillempt])
>
> All this does though, is print glue, where I'd want it to print:
>
> apple
> banana
> eggs
> glue
>
> Perhaps a dictionary isn't the best way to do this.. I wonder what else I can do...
>
> Thanks for any help.
>
You've effectively set up a dictionary with keys 'filled' and 'entries'
which you can see if you run this loop
for key, value in testdict.items():
print(key, value)
which gives me this
empty fish
filled glue
I'm too lazy to type anything else so please refer to this
http://stackoverflow.com/questions/843277/how-do-i-check-if-a-variable-exists-in-python.
I'll also leave the argument over whether it's a variable or a name to
others :)
--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why isn't this code working how I want it to? reubennottage@gmail.com - 2013-10-12 01:56 -0700
Re: Why isn't this code working how I want it to? Marco Nawijn <nawijn@gmail.com> - 2013-10-12 02:17 -0700
Re: Why isn't this code working how I want it to? Peter Otten <__peter__@web.de> - 2013-10-12 11:20 +0200
Re: Why isn't this code working how I want it to? reubennottage@gmail.com - 2013-10-12 04:03 -0700
Re: Why isn't this code working how I want it to? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-12 12:13 +0100
Re: Why isn't this code working how I want it to? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-12 10:39 +0100
Re: Why isn't this code working how I want it to? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-12 12:50 +0300
csiph-web