Skip to content

Instantly share code, notes, and snippets.

@radusuciu
Created July 23, 2016 01:59
Embed
What would you like to do?
sorted_data = sorted(data, key=lambda x: x['Sample name'])
by_sample_name = itertools.groupby(sorted_data, key=lambda x: x.get('Sample name'))
grouped = []
for name, g in by_sample_name:
d = list(g)
grouped.append(
'\t'.join([
name,
str(len(d)),
','.join(set([x['Primary site'] for x in d])),
','.join(set([y['Histology subtype 1'] for y in d]))
])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment