Re: sampling items from a nested list

2005-02-17 Thread Felix Wiemann
Steven Bethard wrote: > py> data = [[('a', 0), > ... ('b', 1), > ... ('c', 2)], > ... > ... [('d', 2), > ... ('e', 0)], > ... > ... [('f', 0), > ... ('g', 2), > ... ('h', 1), > ... ('i', 0), > ... ('j', 0)]] > > I need

Re: sampling items from a nested list

2005-02-16 Thread Michael Spencer
Steven Bethard wrote: Michael Spencer wrote: Steven Bethard wrote: So, I have a list of lists, where the items in each sublist are of basically the same form. It looks something like: ... Can anyone see a simpler way of doing this? Steve You just make these up to keep us amused, don't you? ;-)

Re: sampling items from a nested list

2005-02-16 Thread Michael Spencer
Michael Spencer wrote: >>> def resample2(data): ... bag = {} ... random.shuffle(data) ... return [[(item, label) ... for item, label in group ... if bag.setdefault(label,[]).append(item) ... or len(bag[label]) < 3] ...

Re: sampling items from a nested list

2005-02-16 Thread Steven Bethard
Michael Spencer wrote: Steven Bethard wrote: So, I have a list of lists, where the items in each sublist are of basically the same form. It looks something like: ... Can anyone see a simpler way of doing this? Steve You just make these up to keep us amused, don't you? ;-) Heh heh. I wish. It's

Re: sampling items from a nested list

2005-02-16 Thread Michael Spencer
Steven Bethard wrote: So, I have a list of lists, where the items in each sublist are of basically the same form. It looks something like: ... Can anyone see a simpler way of doing this? Steve You just make these up to keep us amused, don't you? ;-) If you don't need to preserve the ordering, wo