dictionary - Replacing single value in dict in python list comprehension with other items -
currently populating generator networkx
's multidigraph
module, in way:
new_u0_edges = ((u, new_u1, key, edata) u, v, key, edata in self.g.edges_iter(u0, data=true, keys=true) if v == path[0])
but update single key, value
pair in edata
dict, edata['label']
. slow way of doing lists instead of generators is:
new_u0_edges = ((u, new_u1, key, edata) u, v, key, edata in self.g.edges_iter(u0, data=true, keys=true) if v == path[0]) u, new_u1, key, edata in new_u0_edges: edata['label'] = u0[0] + new_u1`
fyi, u0
, new_u1
both strings. yes, debruijn graph in case you're interested.
my question is: is there way modify edata
dict in generator? dict.update([iterable])
doesn't return value necessary generator, , list comprehensions don't seem allow reassigning.
thanks!
update: example variable data (still testing it's silly looking):
u0 = 'defghij' new_u1 = 'efghijklmnabcdefghiwxyz012345' key = 'rna' edata = {'color': '#e41a1c', 'seq_type': 'rna', 'fontcolor': '#e41a1c', 'weight': 1, 'label': 'defghijk (nreads=1)'}
you write function processing you, call generate each element generator. utilize yield
write own generator function rather trying cram in generator statement.
Comments
Post a Comment