def Shard(ilist, shard_index, num_shards):
  """Shard a given list and return the group at index |shard_index|.

  Args:
    ilist: input list
    shard_index: 0-based sharding index
    num_shards: shard count
  """
  chunk_size = len(ilist) / num_shards
  chunk_start = shard_index * chunk_size
  if shard_index == num_shards - 1:  # Exhaust the remainder in the last shard.
    chunk_end = len(ilist)
  else:
    chunk_end = chunk_start + chunk_size
  return ilist[chunk_start:chunk_end]