python如何限制列表被分配元素个数

比如办公室随机分配问题,多个办公室,如何限制每个办公室至多被分配x个人


```python
import random

offices=[[],[],[],[],[]]
names=["A","B","C","D","E","F","G","H","I","J","K","L","M"]
#print(len(names))
for name in names:
    index=random.randint(0,4)
    offices[index].append(name)
i=0
for office in offices:
    print("办公室%d有%d人"%(i,len(office)))
    i+=1
    for name in office:
        print("%s"%name,end='\t')
    print("-"*20)
    print()

```

append之前,先判断一下长度达到极限了没有