for el in vozmozhnye_hody: for el1 in vozmozhnye_hody: if vozmozhnye_hody.index(el)!=vozmozhnye_hody.index(el1): if len(el)<=len(el1): for i in range(len(el1) - len(el)): if el1[i:i+len(el)] == el: del el 

gives the following

 Exception in Tkinter callback Traceback (most recent call last): File "D:\Install\python\lib\lib-tk\Tkinter.py", line 1537, in __call__ return self.func(*args) File "D:\Install\python\shashki1.py", line 74, in obrabotchik_button1 aktivator_shashki(x,y) File "D:\Install\python\shashki1.py", line 87, in aktivator_shashki bit_shashku() File "D:\Install\python\shashki1.py", line 114, in bit_shashku if el1[i:i+len(el)] == el: UnboundLocalError: local variable 'el' referenced before assignment что не так? 
  • one
    Never use Russian words written in Latin letters as identifiers. Use English words. - Vlad from Moscow
  • Never say “never” :-) - MarianD
  • @VladfromMoscow and half an hour google what to call any accounting word in English. - eri
  • @eri Half an hour google, and for the rest of your life the program code will be readable. - Vlad from Moscow

1 answer 1

After you have deleted the el variable in the inner loop:

 del el 

in the next line (in subsequent iterations) you already refer to the nonexistent and undeclared variable el :

 if el1[i:i+len(el)] == el: 
  • those. write after del el break? - Max
  • @ Max, for starters, it’s worth explaining what you are trying to do in this block of code ...;) PS break will only throw you out of the current cycle, and you have them nested - MaxU
  • thanks, I understood the error and already understood how to fix it - Max
  • @ Max, in my opinion, you are trying to invent a bicycle - read about Combinatoric iterators functions from the itertools module - MaxU
  • one
    <off topic> Having learned English at least in a volume sufficient for understanding technical documentation, you will greatly simplify your further communication with programming languages ​​and with IT in general </ off topic>. Google Translate somehow translates official documentation - MaxU pm