There is a list of dataset and I need to reshuffle them randomly then partition the dataset into n groups. I am using dictionary to store the list of dataset, but I am not sure how to partition items of a dictionary into n groups? What I can think of now is that to divide total of keys by n and get 1/n of keys from the dictionary to make n new dictionaries and then start the rest from there. Is this a practical method? Thanks a lot!

it is possible, though simpler is to make a number range of n repeated key_num//n +1 times, shufle and then divide list of keys by taking zip(my_dict.keys(), index_list)

I noticed that better to add random sample of range to fill the not full length in the end as otherwise the lenghts can be not so equal (if many same indexes end up in the end of list in shuffle):

import string
import random
from pprint import pprint
my_dict = dict((c,n) for c,n in zip(string.letters, xrange(53)))
parts = 4
print 'Length of dict', len(my_dict), 'parts', parts
index_list = (len(my_dict)//parts*range(parts) +
random.sample(range(parts), len(my_dict) % parts))
print 'length of index_list:', len(index_list)
random.shuffle(index_list)
mapping = zip(my_dict.keys(), index_list)
dict_list = [ {} for i in range(parts) ]
for key, index in mapping:
dict_list[index][key] = my_dict[key]
for d in dict_list:
print 'Length', len(d)
pprint (d)
print 'Sum of lengths', sum(len(s) for s in dict_list)

I may have some idea about the index_list, it divides total keys into parts(4) groups and put the remainder if any randomly to subgroups, is that right?

Why don't you print out each part of the expression? Maybe cleaner actually to calculate both division and modulo to variables before the expression by divmod function.

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...