Is it proper to use nested loops a lot in python?
From what I understand from your comment, using itertools did solve your problems.

Here are a few suggestions anyway (that you may want to take into account before submitting a new question with the updated code):


instead of using global variables, you should add parameters to your functions.
you could take this chance to add a proper documentation about what your function is supposed to do and what the parameters are.
the indentations seem to be of various sizes. PEP8, the Style Guide for Python code recommands using 4 spaces. It is probably worth reading the whole document.