Q:

fPython : Making a new list from a random list of letters

letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']#alphabet
bag_o_letters = []#letters to chose from
letter_count = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1]#random indexes to chose from
for x in range(26):#loops through the random index of letter_count
    for i in range(letter_count[x]):#chooses the index
        bag_o_letters.append(letters[x])#appends the index of the letter to bag_o_letters
        rack = []#list for the person to see
        for a in range(7):#makes the list 7 letters long
           rack.append(bag_o_letters.pop(random.randint(0,len(letters)-1)))#appends the letter to rack(supposedly...)
print(rack)

In this code that you just read it should choose random letters and put 7 of those letters in a rack that the person can see.  It shows a error that I've looked over many times, but I just can't see what is wrong. 

I put comments on the side to understand the code. 

It shows this error:
rack.append(bag_of_letters.pop(random.randint(0,len(letters)-1)))
IndexError: pop index out of range

Can someone please help? 
After this code, I am going to make a input statement for the user to make a word from those letters. 

A:

You're selecting the index to pop for bag_of_letters from the length of letters which is obviously larger. 
You should instead do:
rack.append(bag_of_letters.pop(random.randint(0, len(bag_of_letters)-1)))
#                                                    ^^^^^^^^^^^^^^

However, there are likely to be more problems with your code.  I'll suggest you use random.sample in one line of code or random.shuffle on a copy of the list, and then slice up till index 7.  Both will give you 7 randomly selected letters:
import random

print(random.sample(letters, 7))
# ['m', 'u', 'l', 'z', 'r', 'd', 'x']

import random

letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
letters_copy = letters[:]
random.shuffle(letters_copy)
print(letters_copy[:7])
# ['c', 'e', 'x', 'b', 'w', 'f', 'v']

