Is it possible to use results from other function into a new list?

I want to make a new list including the results from all three def functions and I do not know how. I am expecting to add all three results from the sites into a new list and then find the lowest price from the list, the highest price, maybe average price(but these i think I can do them by myself).
I am new to coding. Please don’t down vote 🙂

from selenium import webdriver
from import Service
from import Options
from import By
from import WebDriverWait
from import expected_conditions as EC
import time

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 30)

 def bestauto(driver):
    wait.until(EC.element_to_be_clickable((By.ID, 'cookieAccept'))).click()
    block = driver.find_elements(By.XPATH, ".//div[@class='listing-data']")

    result_bestauto = []
    for i in block:
        prices = i.find_element(By.XPATH, ".//strong[@class='price maincolor']").text
        price = prices.strip(' EUR').replace(' ', '.')
    return result_bestauto

def autovit(driver):
    wait.until(EC.element_to_be_clickable((By.ID, 'onetrust-accept-btn-handler'))).click()
    wait.until(EC.element_to_be_clickable((By.XPATH, ".//div[@class='ooa-z4wqde eg0t0xb1']"))).click()
    cars = driver.find_elements(By.XPATH, ".//article[@class='ooa-1txt27o e1b25f6f0']")

    result_autovit = []
    for y in cars:
            car_cost = y.find_element(By.XPATH, ".//span[@class='ooa-1bmnxg7 e1b25f6f11']").text
            cost = car_cost.strip("EUR ").replace(' ', '.')
            au = float(cost)
            au_dec = "{:.3f}".format(au)

    if len(cars) < 6:
        promoted_car = driver.find_element(By.XPATH, ".//article[@class='ooa-1wl9plw e1b25f6f0']")
        pretulMasinii = promoted_car.find_element(By.XPATH, ".//span[@class='ooa-1bmnxg7 e1b25f6f11']").text
        pret = pretulMasinii.strip("EUR ").replace(' ', '.')
        a = float(pret)

    return result_autovit #= class type

def anuntul_ro(driver):
    wait.until(EC.element_to_be_clickable((By.ID, 'acordCookies'))).click()
    masini = driver.find_elements(By.XPATH, ".//div[@class='clearfix line-btw anunt-row i-cb i-pr anunt-w  ']")
    result_anuntul_ro = []
    for x in masini:
        pret_masina = x.find_element(By.XPATH, ".//div[@class='float-right price-list i-fr']").text
        valuare = pret_masina.strip(" €").replace(' ', '.')
        an = float(valuare)
        an_dec = "{:.3f}".format(an)
    return result_anuntul_ro

if __name__ == "__main__":
    result1 = bestauto(driver)
    result2 = autovit(driver)
    result3 = anuntul_ro(driver)
    all_cars = result1 + result2 + result3

>Solution :

You can concatenate the 3 lists into 1 list as following:

import itertools
all_cars = list(itertools.chain(result1, result2, result3))

now you will be able to find minimal and maximal values as following:

minimal_price = min(all_cars)
maximal_price = max(all_cars)

As about average value – there are several ways to get it, I’d prefer this:

average_price = sum(all_cars) / len(all_cars)

Leave a Reply