python3 How to select two elements on either side of a random element in a list?
Question: I have finished this part of the code so far:

    
    
    wedding = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    from random import randrange
    random_index = randrange(0, len(wedding))
    print('TV =', wedding[random_index])
    

I got stuck at a step that I need to find two elements on either side of the
element that I have randomly selected.


Answer: When using arrays, always check for your array bounds in your code. The below
code will output the value from the array that is to the left and right of the
randomly selected index value. If either of the indexes are out of bounds, it
will not output that value.

    
    
    from random import randrange 
    
    wedding = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 
    random_index = randrange(0, len(wedding)) 
    
    print('TV = ', wedding[random_index])
    
    if random_index-1 >= 0:
        print('Left of Index = ', wedding[random_index-1])
    if random_index + 1 < len(wedding) - 1:
        print('Right of Index = ', wedding[random_index + 1])
    

