Apr. 27th, 2014

helloworld: (Default)
Since I'm always forgetting it, I'm putting it here. Original is from Stack Overflow, but I made changes to make it work with defaultdict. Also, I use Python 3, just putting it out there.

The original code:

>>> max(testDict, key=lambda x:len(testDict[x]))
32

If multiple keys contain the longest list:

>>> testDict = {76: [4], 32: [2, 4, 7, 3], 56: [2, 58, 59], 10: [1, 2, 3, 4]}
>>> mx = max(len(x) for x in testDict.itervalues())
>>> [k for k, v in testDict.iteritems() if len(v)==mx]
[32, 10]
My version, where probes is my dictionary (working off an Affy Exome array, in case you were wondering ... you probably weren't ...)
mx = max(len(x) for x in probes.values())
mxx = [k for k, v in probes.items() if len(v)==mx]

(And then return whatever it is you need.)

Profile

helloworld: (Default)
apply(myLife, fuck)

October 2015

S M T W T F S
    123
4 5678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags