Returning two randomly chosen groups from a list in python
Question: How would i write code that involves having a list of 9 people split as evenly
as possible into 2 cars but they are placed into each car randomly in python?
Essentially i'm looking for a return similar to this:  
Car 1: Person8, Person2, Person4, Person7  
Car 2: Person5, Person1, Person3, Person6, Person9


Answer: Just shuffle the whole list, then just split that list into two chucks, one
with 4 people and one with the remainder:

    
    
    import random
    
    people = ['foo', 'bar', 'baz', 'eggs', 'ham', 'spam', 'eric', 'john', 'terry']
    random.shuffle(people)
    car1, car2 = people[:4], people[4:]
    

If you can't sort the list of people directly, use `random.sample()` instead:

    
    
    people = ['foo', 'bar', 'baz', 'eggs', 'ham', 'spam', 'eric', 'john', 'terry']
    shuffled = random.sample(people, len(people))
    car1, car2 = shuffled[:4], shuffled[4:]
    

Demo of the latter approach:

    
    
    >>> import random
    >>> people = ['foo', 'bar', 'baz', 'eggs', 'ham', 'spam', 'eric', 'john', 'terry']
    >>> shuffled = random.sample(people, len(people))
    >>> shuffled[:4], shuffled[4:]
    (['bar', 'baz', 'terry', 'ham'], ['spam', 'eric', 'foo', 'john', 'eggs'])
    

