Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-27 Thread Andreas Perstinger
On 2011-11-26 03:49, lina wrote: for k, v in occurence.items(): print(v,k) 292 frozenset({66, 69}) 222 frozenset({24, 27}) How can I let the result like: 292 {66,69} 222 {24,27} don't output the frozenset If you want to use your own output format you have to provide

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Sat, Nov 26, 2011 at 12:49 AM, Andreas Perstinger wrote: > On 2011-11-25 13:40, lina wrote: >> >> On Fri, Nov 25, 2011 at 7:19 PM, Steven D'Aprano >>  wrote: >>> >>>  f = open("some file") >>>  dehydrons = {} >>>  occurrence = {} >>>  pairs = {} >>>  for line in f.readlines(): >>>     parts = l

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Andreas Perstinger
On 2011-11-25 13:40, lina wrote: On Fri, Nov 25, 2011 at 7:19 PM, Steven D'Aprano wrote: f = open("some file") dehydrons = {} occurrence = {} pairs = {} for line in f.readlines(): parts = line.split() # convert to ints parts = [int(s) for s in parts] pair = frozenset(pa

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 7:19 PM, Steven D'Aprano wrote: > lina wrote: >> >> On Fri, Nov 25, 2011 at 5:06 PM, Steven D'Aprano >> wrote: > >>> pair = frozenset(('66', '69')) >>> pairs[pair] = pairs.get(pair, 0) + value >> >> I don't get this "pairs.get" part. > > The "get" method does a look-up on

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Alan Gauld
On 25/11/11 08:41, lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: here is the (failed) code: for k, v in pair

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Steven D'Aprano
lina wrote: On Fri, Nov 25, 2011 at 5:06 PM, Steven D'Aprano wrote: pair = frozenset(('66', '69')) pairs[pair] = pairs.get(pair, 0) + value I don't get this "pairs.get" part. The "get" method does a look-up on a dict, but instead of failing if the key is missing, it returns a default val

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
for key, value in pairs.items(): if key[::-1] in pairs.keys() and pairs[key] != 0: pairs[key] += pairs[key[::-1]] pairs[key[::-1]]=0 for k, v in pairs.items(): if v != 0: print(v,k) Now very trivial, but works.

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
#!/usr/bin/python3 dehydrons={} pairs={} #frozen set way pairs fs_pairs={} occurence={} total=0 dictionary={} candidate_dehydron={} if __name__=="__main__": with open("dehydron_refined_data_18.txt","r") as f: for line in f.readlines(): parts=line.split() #pai

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 5:19 PM, Christian Witts wrote: > On 2011/11/25 11:15 AM, lina wrote: > > On Fri, Nov 25, 2011 at 5:05 PM, Christian Witts > wrote: > > On 2011/11/25 10:41 AM, lina wrote: > > pairs > > {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} > > > such as here ('66', '69')

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 5:06 PM, Steven D'Aprano wrote: > lina wrote: > > pairs >> >> {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} >> >> >> such as here ('66', '69') and ('69', '66') is one key, >> >> I wanna keep only one and add the value of those two keys, above is a >> very

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Christian Witts
On 2011/11/25 11:15 AM, lina wrote: On Fri, Nov 25, 2011 at 5:05 PM, Christian Witts wrote: On 2011/11/25 10:41 AM, lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of th

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
On Fri, Nov 25, 2011 at 5:05 PM, Christian Witts wrote: > On 2011/11/25 10:41 AM, lina wrote: > > pairs > > {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} > > > such as here ('66', '69') and ('69', '66') is one key, > > I wanna keep only one and add the value of those two keys, above is a

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Christian Witts
On 2011/11/25 10:41 AM, lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: here is the (failed) code: for k, v in

Re: [Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread Steven D'Aprano
lina wrote: pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: Which one do you want to keep? If the order ('66', '69') is unimporta

[Tutor] how to delete some quasi-duplicated keys

2011-11-25 Thread lina
>>> pairs {('66', '69'): 217, ('69', '66'): 75, ('64', '71'): 25} such as here ('66', '69') and ('69', '66') is one key, I wanna keep only one and add the value of those two keys, above is a very simple example: here is the (failed) code: for k, v in pairs.items(): if str(k