Skip to content

Instantly share code, notes, and snippets.

@acmisiti
Last active August 29, 2015 14:16
Show Gist options
  • Save acmisiti/a16715097f1898a55134 to your computer and use it in GitHub Desktop.
Save acmisiti/a16715097f1898a55134 to your computer and use it in GitHub Desktop.
def get_reporting(data):
if not data:
return (0, 0)
unique_ids = list(set(data))
num_unique_vistors = len(unique_ids)
# create frequency of visits by user id dict
frequency = dict((key, len([k for k in data if k == key])) for key in unique_ids)
# get average page views per user
avg = sum(frequency.values())/float(num_unique_vistors)
return (num_unique_vistors, avg)
dataset1 = [8, 8, 2, 2]
assert get_reporting(dataset1) == (2, 2.0)
dataset2 = [9, 8, 9]
assert get_reporting(dataset2) == (2, 1.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment