On Mon, May 2, 2016 at 5:28 PM Jason N. via Tutor wrote:
> Hello,
> Wanted to ask if its possible to have a dictionary that can be looked up
> by either values?
> For example,
> mydic = {"A: "Apple", "B": "Banana"}When user inputs "A" I want "Apple" to
> come. But if the user enter "Apple" I want
On Mon, May 2, 2016 at 8:58 PM Jason N. via Tutor wrote:
> What is the best way to make dictionary requests case in-sensitive? For
> example, "Apple and "apple" should bring back the same dictionary
> response. Thank you.
>
Take a look at how the requests library solves the problem with a
"CaseI
Hello,
Using iteritems would be much easier approach
Something like this
mydic = {"A": "Apple", "B": "Banana"}
for key, value in mydic.iteritems(): if value == "Apple": print key
Thanks & BR, Bharath Shetty
On Tuesday, 3 May 2016 2:57 AM, Jason N. via Tutor wrote:
Tha
On 03May2016 00:56, Jason N. wrote:
Thank you all for your responses.
A quick follow up, what is the best way to make dictionary requests case
in-sensitive? For example, "Apple and "apple" should bring back the same
dictionary response. Thank you.
There are a few ways depending what your mo
If only I understand what you mean. You can just make all the values in the
dictionary lower, upper or capitalized. Then if you want take an input or
whatever you want to do with it just use .lower() or .upper() or .capitalized()
to convert it to what is in the dictionary. Maybe someone has a be
Thank you all for your responses.
A quick follow up, what is the best way to make dictionary requests case
in-sensitive? For example, "Apple and "apple" should bring back the same
dictionary response. Thank you.
On Monday, May 2, 2016 6:57 PM, Bob Gailer wrote:
On May 2, 2016 5:27
On May 2, 2016 5:27 PM, "Jason N. via Tutor" wrote:
>
> Hello,
> Wanted to ask if its possible to have a dictionary that can be looked up
by either values?
> For example,
> mydic = {"A: "Apple", "B": "Banana"}When user inputs "A" I want "Apple"
to come. But if the user enter "Apple" I want "A" to
On 02/05/16 22:55, isaac tetteh wrote:
>
> For some reason i cant find reply all . But try this
> for key, value in mydic.items():
> If A==value:
>Print key
or as a function:
def findKey(dct, val):
for k,v in dct.items():
if v == val:
return k
mydic = {"A: "
Sorry for the if statement the correct statement should be "if 'apple' ==value:"
Sent from my iPhone
> On May 2, 2016, at 4:58 PM, isaac tetteh wrote:
>
>
> For some reason i cant find reply all . But try this
> for key, value in mydic.items():
> If A==value:
> Print key
> Nb:
For some reason i cant find reply all . But try this
for key, value in mydic.items():
If A==value:
Print key
Nb: use iteritems() if using python2
Sent from my iPhone
> On May 2, 2016, at 4:29 PM, Jason N. via Tutor wrote:
>
> Hello,
> Wanted to ask if its possible to have a d
On Wed, 22 Dec 2010 23:31:39 +1100, Steven D'Aprano wrote:
> In this case, you need to sum the number of races for all the fixtures:
>
> num_races = sum(len(racetimes) for racetimes in FixtureDict.values())
Many thanks Steven for your explanation and final golden nugget of code.
On Wed, 22 Dec 20
On 12/22/2010 7:31 AM, Steven D'Aprano wrote:
Also note: len(dict.keys()) == len(dict.values()) == len(dict)
--
Bob Gailer
919-636-4239
Chapel Hill NC
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.p
Garry Bettle wrote:
Howdy all,
Hope this message finds everyone well.
I have dictionary of keys and a string of values.
i.e.
8 Fixtures:
I assume each fixture is a key, e.g. Swin, HGrn, etc.
Swin1828 1844 1901 1916 1932 1948 2004 2019 2036 2052 2107 2122
HGrn1148 1204 1218 1232 12
> I should have known. sheesh python is so kewl. I keep forgetting most
> times,
> it will do stuff directly and you don't have to assign..
Whether thats 'kewl' depends on your viewpoint.
>From a pure computing point of view returning a value is more consistent
and correct in a functional program
ahh man,
I should have known. sheesh python is so kewl. I keep forgetting most times,
it will do stuff directly and you don't have to assign..
Thanks
Python Newbie
On Friday 11 November 2005 02:59 pm, DS wrote:
> You almost have it. Do this instead.
>
> d = {'first':[]}
> d['first'].appe
You almost have it. Do this instead.
d = {'first':[]}
d['first'].append("string")
Append acts on the list, so assignment is unnecessary.
ds
Eric Walker wrote:
>All,
>I have a dictionary say:
>d = {'first':[]}
>I am going through another list and depending on whats going on,
>I want to add to t
On 11/11/05, Eric Walker <[EMAIL PROTECTED]> wrote:
> All,
> I have a dictionary say:
> d = {'first':[]}
> I am going through another list and depending on whats going on,
> I want to add to the empty list. I have tried the following to noavail.
>
> d['first'] = d['first'].append("string")
>
> I wo
David Driver wrote:
> If I
> create a dictionary with the same keys, will it str the same way?
This behaviour is not guaranteed and I wouldn't depend on it. It can break if
any other operations have happened on the dict; for example
>>> d=dict(a=1,b=2,c=23)
>>> str(d)
"{'a': 1, 'c': 23, 'b': 2
18 matches
Mail list logo