Skip to content

Instantly share code, notes, and snippets.

View californiacal's full-sized avatar

Cal californiacal

View GitHub Profile
sentence = 'there was once a fox who there enjoyed tea there was once a fox who there enjoyed tea tea'
words = sentence.split()
counts = {}
for word in words:
counts[word] = counts.get(word, 0) + 1
top3 = sorted(count.items(), key=lambda x: x[1], reverse=True)[:3]
print(top3)
@mb0017
mb0017 / Python-Quicksort.py
Created January 15, 2014 21:46
Quicksort using list comprehensions
#source: http://en.literateprograms.org/Quicksort_(Python)
def qsort1(list):
"""Quicksort using list comprehensions"""
if list == []:
return []
else:
pivot = list[0]
lesser = qsort1([x for x in list[1:] if x < pivot])
greater = qsort1([x for x in list[1:] if x >= pivot])
return lesser + [pivot] + greater