Skip to content

Instantly share code, notes, and snippets.

@kamanazan
Created March 14, 2018 08:10
Show Gist options
  • Save kamanazan/75489fb791be3e7e493001dd89670beb to your computer and use it in GitHub Desktop.
Save kamanazan/75489fb791be3e7e493001dd89670beb to your computer and use it in GitHub Desktop.
from collections import defaultdict
def gen_dict(a):
d = defaultdict(list)
# the score would be look like this [('image_name', response_time)...]
# Group the list by image_name and combine the score
for k,v in a:
d[k].append(v)
# Output: defaultdict(<type 'list'>, {'a': [1, 2, 3], 'c': [1, 2, 3], 'b': [1, 2, 3]})
# >>> d['a']
# [1, 2, 3]
# We flatten it into a list of list and later save it as csv
score_list = []
for name, score in d.iteritems():
x = [name]
x.extend(score)
score_list.append(x)
# >>> score_list
# [['a', 1, 2, 3], ['c', 1, 2, 3], ['b', 1, 2, 3]]
return score_list
# PoC
import random
images = 'ABCDEFGHIJKLMN'
image_set = list(images) * 12
random.shuffle(image_set)
scores = [random.randint(50,200) + random.random() for x in image_set]
result = zip(image_set, scores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment