I have a chunk of code that I know is way too long for the rather simple output I get. It is simply creating a list of items found within a list of websites. It then assigns the text from each of those items in the list to a Tkinter label and positions each of those labels in a distinct row and column inside a grid. So if I had four websites, and seven items found on each of those four websites, I would have 28 labels to create, and 28 grid locations. I have posted the snipped of the code, along with a link to the entire file code below if you would like to open and run it. Would someone please be able to show me a better way of writing this? (Am just a beginner)Snippetloop_count = 1watch_model_description_list = []watch_model_description_grid_list = []for num, url in enumerate(watch_link_urls):    dennisov_model_html = urlopen(url).read()    dennisov_model_html = dennisov_model_html.replace('', ')    watch_model_description = findall(dib_02'\>([A-Z \/0-9]+)\<, dennisov_model_html)    for number, category in enumerate(watch_model_description):                 watch_model_description = 'category_' + str(loop_count) + ' = Label(window, font = (Helvetica, 5), text = '+ category +')'        watch_model_description_grid = 'category_' + str(loop_count) + '.grid(padx = 0, pady = 0, row = ' + str(number+3) + ', column = '+ str(num) +')'        watch_model_description_list.append(watch_model_description)        watch_model_description_grid_list.append(watch_model_description_grid)        loop_count += 1model_option = {'model_{}'.format(i):e for i, e in enumerate(watch_model_description_list)}model_grid_option = {'model_grid{}'.format(i):e for i, e in enumerate(watch_model_description_grid_list)}model_grid_option_string = '\n'.join(model_grid_option.values())model_option_string = '\n'.join(model_option.values())exec(model_option_string)exec(model_grid_option_string)File codefrom Tkinter import Tk, Button, Canvas, END, Spinbox, PhotoImage, Labelfrom ttk import Progressbar, Comboboxfrom urllib import urlopenfrom re import findallimport urllib## Create a windowwindow = Tk()## Give the window a titlewindow.title('Watch finder')## Show Dennisov image logodennisov_logo_url = http://i.imgur.com/KD6AK08.gifhandle = urlopen(dennisov_logo_url)data = handle.read()raw_image = PhotoImage(master = window, data = data)Label(window, image = raw_image, width = 600).grid(row = 0, column = 0, columnspan = 10)handle.close## Types of Dennisov watches - INTRODUCE THE WATCH NAMES FUNCTION HERE AS THIS IS## HARDCODEDdennisov_type_list = ['Barracuda Limited','Barracuda Chronograph',                      'Barracuda Mechanical','Speedster','Free Rider',                      'Nau Automatic','Lady Flower','Enigma','Number One']## Open a new HTML file enable writing to itdennisov_file = open('dennisov_url.html', 'w')## Begin writing to HTML filedennisov_file.write('''<!DOCTYPE html><html>    <head>        <title>Watches</title>    </head>    <body>''')  dennisov_file.write('''</body></html>''')## Define function for selection button pushdef show_models():## Make function read from user dropdown box selection    dennisov_type_selection = (dennisov_dropdown_box.get())## Convert to lower-case and replaces spaces with _ to be used in URL    dennisov_type = dennisov_type_selection.lower().replace(' ','_')## Complete the Dennisov URL using the converted user name selection    dennisov_url = 'https://denissov.ru/en/'+ dennisov_type + '/'## Make a varibale for the Dennisov subpage from the URL domain onwards    dennisov_url_subpage = dennisov_url[19:]## Read the Dennisov URL HTML    dennisov_html = urlopen(dennisov_url).read()## Replace instances of double quotation marks in the text with singles ## so that the findall regex code does not get confused     dennisov_html = dennisov_html.replace('', ')## Find all of the images of the watches. Each watch image starts with the text## img src=. Do not match those with any  symbols in the URL    watch_image_urls = findall(<img src='(/files/collections/o[^']*)', dennisov_html)## Add the URL domain to each watch image subpage to create full addresses    watch_image_urls = ['https://denissov.ru' + remainder for remainder in watch_image_urls]##    dennisov_file.write('        <img src=' + image + '>\n')## Download and save the PNG images to the directory as GIFs so that## Tkinter can use them## Return the watch 'type'. The watch type is in a title tag called titlusref## and can be any combination of letters and spaces, followed by a space and## < symbol.     watch_type = findall(titlusref'\>([a-zA-Z]+ *[a-zA-Z]*) *\<, dennisov_html)[0]## Find all of the links when each watch is clicked. Each watch link starts## with the text a href= followed by the subpage, followed by any## letter, number and _ symbol combination, followed by a backslash    watch_link_urls = findall(a href=' + (dennisov_url_subpage) + ([A-Za-z0-9_]+/), dennisov_html)  ## Add the main URL to each watch subpage    watch_link_urls = [str(dennisov_url) + remainder for remainder in watch_link_urls]## Find all of the model numbers of each watch. Each model starts with the text## covername then any combination of letters, dots and spaces.     watch_names = findall(covername'>([A-Z a-z0-9\.]+), dennisov_html)## Get current USD to AUD exchange rate using a known currency website    currency_converter_url = 'http://www.xe.com/currencyconverter/convert/?From=USD&To=AUD'    currency_html = urlopen(currency_converter_url).read()## Replace instances of double quotation marks in the text with singles ## so that the findall regex code does not get confused     currency_html = currency_html.replace('', ')## Find the exchange rate. The exchange rate starts with uccResultAmount'>## and is then followed by any combination of numbers with a decimal place    exchange_rate = float(findall(uccResultAmount'\>([0-9]+\.[0-9]*), currency_html)[0])## Find the price of the models and make into floats. Each model price contains## numbers followed by the text USD    USD_watch_prices = [float(price) for price in (findall(([0-9]*) usd, dennisov_html))]## Convert the USD watch prices to current AUD prices and round to 2 decimals    watch_prices = [round(exchange_rate*price, 2) for price in USD_watch_prices]## Add the currency to the prices    watch_prices = [AU $ + str(price) for price in watch_prices]## Match each watch name to its image and URL inside a tuple and place each## tuple inside a list    watch_list = zip(watch_names, watch_image_urls, watch_prices, watch_link_urls)## For each watch tuple (matching image, name and URL), assign a watch number    watch_option = {'watch_{}'.format(i): e for i, e in enumerate(watch_list)}## CREATE A LIST OF MODEL DESCRIPTIONS ACCORDING TO THE TYPE OF WATCH SELECTED:## > Read each model HTML link in watch_link_urls.## > Search for the terms inside each URL that start with dib_02 followed by any ## combination of capital letters, numbers and backslashes.## > Insert Label and Label grid attributes to each result using a counter to keep track ## of overall loops in order to create unique names and locations. ## > Append the results of each loop to a list called watch_model_description_list ## > Place the results into a dictionary so that the values can be extracted from the ## lists easily, converted to strings and then executed     loop_count = 1    watch_model_description_list = []    watch_model_description_grid_list = []    for num, url in enumerate(watch_link_urls):        dennisov_model_html = urlopen(url).read()        dennisov_model_html = dennisov_model_html.replace('', ')        watch_model_description = findall(dib_02'\>([A-Z \/0-9]+)\<, dennisov_model_html)        for number, category in enumerate(watch_model_description):                     watch_model_description = 'category_' + str(loop_count) + ' = Label(window, font = (Helvetica, 5), text = '+ category +')'            watch_model_description_grid = 'category_' + str(loop_count) + '.grid(padx = 0, pady = 0, row = ' + str(number+3) + ', column = '+ str(num) +')'            watch_model_description_list.append(watch_model_description)            watch_model_description_grid_list.append(watch_model_description_grid)            loop_count += 1    model_option = {'model_{}'.format(i):e for i, e in enumerate(watch_model_description_list)}    model_grid_option = {'model_grid{}'.format(i):e for i, e in enumerate(watch_model_description_grid_list)}    model_grid_option_string = '\n'.join(model_grid_option.values())    model_option_string = '\n'.join(model_option.values())    exec(model_option_string)    exec(model_grid_option_string)## Create the Spinboxes for each watch model    global spinboxes    spinboxes = []    spinbox_grid_list = []    for number, name in enumerate(watch_names):        spinboxes.append(Spinbox(window, width = 3, from_= 0, to = 10))        spinboxes[number].grid(padx = 0, pady = 0, row = 13, column = number)## Create the prices for each watch model        prices = []    prices_grid_list = []    for number, price in enumerate(watch_prices):        prices.append(Label(window, font = (Helvetica, 10), text = price))        prices[number].grid(padx = 0, pady = 0, row = 12, column = number)               ## Create the names for each watch model    names = []    names_grid_list = []    for number, name in enumerate(watch_names):        names.append(Label(window, font = (Helvetica, 10), text = name))        names[number].grid(padx = 0, pady = 0, row = 2, column = number)  ## Create a Create Invoice button    invoice_button = Button(window, text = 'Create Invoice', command = create_invoice, width = 20)    invoice_button.grid(pady = 10, padx = 2, row = 16, columnspan = 9, sticky = S) ## Define an action for what the Create Invoice button is pushed def create_invoice():    for i, spinbox in enumerate(spinboxes):        print 'spinbox_{} = '.format(i) + (spinbox.get())## Create dropdown box textdennisov_dropdown_text = Label(window, text = Watch type:, bg = 'White', width = 20)## Create the dropdown box for the Dennisov watch typesdennisov_dropdown_box = Combobox(window, width = 25,                                  values = dennisov_type_list)## Create Dennisov type selection buttondennisov_select_button = Button(window, text = 'Select', command = show_models, width = 20)## Locate elements on griddennisov_dropdown_text.grid(pady = 2, padx = 2, row = 1, columnspan = 9, sticky = 'W')dennisov_dropdown_box.grid(pady = 2, padx = 2, row = 1, columnspan = 9, sticky = 'N')dennisov_select_button.grid(pady = 2, padx = 2, row = 1, columnspan = 9, sticky = 'E')dennisov_file.close()window.mainloop()
Code that extracts items from a list of websites and creates Tkinter text labels using their values
python;beginner;python 2.7;tkinter