|
What's the best way to group x amount of items into y amount of groups based on a variable property of each item eg. weight.
Leaving me with y amount of groups each holding the same sum(price) (or close to the same). So the groups are balanced by cumulative...
Started by Christo Du Preez on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
;(); for (V item : items) { K key = item.getProperty(); Set<V> group = results.get(key); if (group == null) { group = new HashSet<V>(); results.put(key, group); } group.add(item); }
Where V ....
|
|
I want to write a function that takes items from a list and groups them into groups of size n.
Ie, for n = 5, [1, 2, 3, 4, 5, 6, 7] would become [[1, 2, 3, 4, 5], [6, 7]].
What's the best python idiomatic way to do this?
Started by Scotty Allen on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
""" blocks = [] for....
If the number of items in the iterator doesn't divide by blocksize, a smaller block containing the remaining items is added to the result.
): """Split the items in the given iterator into blocksize-sized lists.
|
|
I am using the MySQL GROUP BY function, and want to know if there is a way to get the number of items for that group without having to a query again?
$homePointsPlayerResult = mysql_query("SELECT `player_id` FROM `conversions` WHERE `game_id` = '$game...
Started by Anriƫtte Combrink on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Id` = '$game_id' AND `team_id` IS NULL GROUP BY `player_id`
Just add another column to the SELECT.
|
Ask your Facebook Friends
|
I am scratching my head trying to do this and it's eating me up. I know it is not THAT complex. I have a number of items, this number can be equal or greater than three. Then I need to determine the possible combination of group of items that will complete...
Started by miguelrios on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Import sys # All partitions for a particular n: def groups(n, base, minBase, sum, sets, group = []): c = 0; i = (n - sum) / base while i >= 0: s = sum + base * i if s == n: sets.append(group, (group + [i])) i = i - 1 return....
|
|
I'm often confronted with the following situation: I have some data in a table (nested arrays) and need to loop over all items in it.
Requirements:
The first item should be identified and handled separately. The last item should be identified and handled...
Started by capfu on
, 3 posts
by 2 people.
Answer Snippets (Read the full thread at stackoverflow):
I); String group; out.print("First Entry:" + format(row)); Map<String, Integer> subTotals = new HashMap<String, Integer>(); do { group = col(row, groupBy); out.print("First " + group + ":"); subTotals.put(group....
|
|
I have some rows in a database which represent line items in a sale. Each line item has five columns:
id : Primary key. sale_id : The sale that this line-item is a part of (a foreign key to a Sales table). product_id : The product this item corresponds...
Started by Kyle Kaitan on
, 3 posts
by 2 people.
Answer Snippets (Read the full thread at stackoverflow):
Array_unshift( $data[$row['group']], $row_query_here ); while( $row = mysql_fetch_assoc( $result ) ) { if( !isset( $data[$row['group']] ) ) { $data[$row['group']]....
Put the item at at the front of the array by unshifting it.
|
|
Hi,
A newbie question which I could not find an answer to.
I have a report containing a table holding several items that have a "Time" Column. I would like to group the items by time so that all items of the same month will be grouped together.
To do ...
Started by Ben on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Designing-birt-reports/746-create-a-dynamic-group-by-extracting-a-substring/#description
Good Luck column based on isoyyyymm and blank out for that column in the table:
the heading, the group data line | Value | + + + + | <Group....
|
|
I have a combobox in Silverlight, whose itemssource is bound with a CollectionView of CollectionViewSource .
I have also added GroupDescription to the CollectionView .
Now I need to display the items in ComboBox grouped and also need to display the group...
Started by NKC1 on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Would it be sufficient to just sort the items itemtemplate? The combobox....
Before binding the combobox and then displaying both the group name and the item name in the comboboxThe Silverlight combobox does not support grouping.
|
|
I have a list like
<ul> <li> hgh55jjj </li> <li> abc99xyz </li> <li> hgf88hjk </li> <li> </li> <li> </li> <li> def99bnb </li> <li> gjj77hkj </li> <li> hgh5...
Started by Indraneel on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
And places them in an associated array, based on the key:
var items = $('li'); var groups] = []; groups[g].push(li); });
Finally, for every group we create it's own <ul> , with name=id=List99 (this will help when you....
|
|
Hello,
say I have such model:
class Foo(models.Model): name = models.CharField("name",max_length=25) type = models.IntegerField("type number")
after doing some query like Foo.objects.filter(), I want to group the query result as such:
[ [{"name":"jb",...
Started by Hellnar on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
You can do this with the values method of a queryset:
http://docs.djangoproject.com/en/1.1/ref/models/querysets/#values-fields
values(*fields)
Returns a ValuesQuerySet -- a QuerySet that evaluates to a list of dictionaries instead of model-instance objects... .
|