match « tuple « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » tuple » match 

1. Look up a tuple in a python dictionary matching (x,y) or (y,x)    stackoverflow.com

I've a dictionary with a (x,y) key, where (x,y) means the same as (y,x), How should I do this ? I can do:

>>> d = {(1,2): "foo"}
>>> i = d.get(2,1)
>>> if i ...

2. One element of a tuple dict-key matching in Python    stackoverflow.com

If I have a dict such as:

foo = {('foo', 45):5, ('bar', 34):3}
How can I check against part of that tuple?
if 'foo' in foo: #should be true
    pass
if 45 ...

3. Python, removing whole list if it contains a matching tuple    stackoverflow.com

I hope this hasn't been asked before but it's hard for me to put into words what it is I'm trying to do! It might be easier if I explain my input, ...

4. In python how can I match two lists of tuples by a tuple element?    stackoverflow.com

Let's say I have names as a list of tuples that contain name tuples in arbitrary order:

names = [(1,"Alice"), (2,"Bob")]
and genders as another list of tuples that contain gender tuples in ...

5. Help using *args in tuple matching Python function    stackoverflow.com

I am trying to build a function in python that yields values of two dictionaries IF a particular value from dict1 matches a particular value of dict2. My function looks like ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.