When browsing the keys of a dictionary, you can use the ``.keys()`` method but
that is in fact only really useful if you want to store the list of keys first
and act on them (like sorting them or so).
If you just want to iterate through all the keys, no matter the order, then it
is much much faster to just do: ``for key in dict``
Some stats about this can be found there:
http://blog.pingoured.fr/index.php?post/2012/03/12/Python-notes-to-self
Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Reviewed-by: Simo Sorce <simo@redhat.com>
if g in globals():
globals()[g] = val
else:
if g in globals():
globals()[g] = val
else:
- for k in globals().keys():
if k.lower() == g.lower():
globals()[k] = val
break
if k.lower() == g.lower():
globals()[k] = val
break
if g in globals():
globals()[g] = val
else:
if g in globals():
globals()[g] = val
else:
- for k in globals().keys():
if k.lower() == g.lower():
globals()[k] = val
break
if k.lower() == g.lower():
globals()[k] = val
break
else:
data = idp.get_data()
else:
data = idp.get_data()
- for idval in data.keys():
result = dict(provider=data[idval].get('name'),
metadata=data[idval].get('metadata'),)
results.append(result)
result = dict(provider=data[idval].get('name'),
metadata=data[idval].get('metadata'),)
results.append(result)
@classmethod
def get_connection(cls, name):
@classmethod
def get_connection(cls, name):
- if name not in cls.__instances.keys():
+ if name not in cls.__instances:
if cherrypy.config.get('db.conn.log', False):
logging.debug('SqlStore new: %s', name)
cls.__instances[name] = SqlStore(name)
if cherrypy.config.get('db.conn.log', False):
logging.debug('SqlStore new: %s', name)
cls.__instances[name] = SqlStore(name)
# If ignore_case is True,
# then PD translates case insensitively prefixes
PD = dict()
# If ignore_case is True,
# then PD translates case insensitively prefixes
PD = dict()
- for k in attributes.keys():
if ignore_case:
# note duplicates that differ only by case
# will be lost here, beware!
if ignore_case:
# note duplicates that differ only by case
# will be lost here, beware!
nameid='unspecified'):
newconf = ConfigParser.ConfigParser()
newconf.add_section('globals')
nameid='unspecified'):
newconf = ConfigParser.ConfigParser()
newconf.add_section('globals')
- for k in global_opts.keys():
newconf.set('globals', k, global_opts[k])
newconf.add_section('arguments')
newconf.set('globals', k, global_opts[k])
newconf.add_section('arguments')
- for k in args_opts.keys():
newconf.set('arguments', k, args_opts[k])
profile = io.BytesIO()
newconf.set('arguments', k, args_opts[k])
profile = io.BytesIO()
data.pop('MELLON_IDP')
data.pop('MELLON_NAME_ID')
data.pop('MELLON_IDP')
data.pop('MELLON_NAME_ID')
- for key in expected.keys():
item = data.pop('MELLON_' + key)
if item != expected[key]:
raise ValueError('Expected %s, got %s' % (expected[key], item))
item = data.pop('MELLON_' + key)
if item != expected[key]:
raise ValueError('Expected %s, got %s' % (expected[key], item))
splist = []
spport = 45081
splist = []
spport = 45081
- for nameid in SAML2_NAMEID_MAP.keys():
+ for nameid in SAML2_NAMEID_MAP:
nameid = nameid
spdata = {'nameid': nameid, 'addr': '127.0.0.11', 'port': str(spport)}
splist.append(spdata)
nameid = nameid
spdata = {'nameid': nameid, 'addr': '127.0.0.11', 'port': str(spport)}
splist.append(spdata)