Partition function with itertools from itertools import izip_longest

def partition(n, iterable):
   p = izip_longest(*([iter(iterable)] * n))
   r = []
   for x in p:
       s = set(x)
       s.discard(None)
       r.append(list(s))
   return r

print partition(2, range(100))


I saw it from a recruit and the company said there were potential problems, but I can't find out anything wrong with my test case:

print partition(2, range(100))
print partition(1, range(100))
print partition(-1, range(100))
print partition(101, range(100))
The elephants in the room:


Single letter variable names are to be avoided. Each variable should have a suggestive meaningful name.
They probably expected you to write automated tests, just printing a result for visual inspection is not a real way of testing. assert is easy to use and can get you started on automated testing.