User talk:Tonyjv: Difference between revisions

Line 48:
 
:::P.S. I try and not make the assumption that better==faster. There are other considerations to take into account. Having said that, your faster example above has a certain elegance... --[[User:Paddy3118|Paddy3118]] 06:03, 21 September 2011 (UTC)
That will not run in Python 3 as bytes can not be joined, here is my fastest version not using groupby, did not compare with the non-groupby version in the page under discussion:
<lang python>
from collections import defaultdict
d = defaultdict(list)
t0 = time.clock()
for w in words:
d["".join(sorted(str(w)))].append(w)
 
d=sorted(d.values(), key=len, reverse=True)
lm = len(d[0])
for value in d:
if (len(value) == lm):
print(value)
else:
break
t0 -= time.clock()
print('Finished in %f s\n' % -t0)
 
</lang>
Anonymous user