Skip to content

Instantly share code, notes, and snippets.

@radusuciu
Created July 23, 2016 01:59
Show Gist options
  • Save radusuciu/4bd636991702984bb7eb76dba6a7c916 to your computer and use it in GitHub Desktop.
Save radusuciu/4bd636991702984bb7eb76dba6a7c916 to your computer and use it in GitHub Desktop.
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