[[['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], [['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], и так n-раз]
[['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], ['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], и так n-раз]
lt=[['Volvo', 'Xc90', '2017', 'Gray',['A','B','C','D'], '2.0L'], 'YV4102XK8H1144180', 'Copart',
'69990071', 'Run And Drive', 'Side', '33554 мили (Actual)',
['Volvo', 'Xc90', '2017', 'Gray', '2.0L'],'07.02.2022']
def fl_list(l):
fl=[]
for sl in l:
if type(sl)!=list:
fl.append(sl)
else:
fl=fl+fl_list(sl)
return fl
flt=fl_list(lt)
print(flt)
['Volvo', 'Xc90', '2017', 'Gray', 'A', 'B', 'C', 'D', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', 'Volvo', 'Xc90', '2017', 'Gray', '2.0L', '07.02.2022']
def expand(data: list):
for value in data:
if hasattr(value, '__iter__') and not isinstance(value, (str, bytes)):
yield from expand(value)
else:
yield value
data = [[['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], [['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022']]
expanded_data = []
for d in data:
expanded_data.append(list(expand(data)))
[['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022', 'Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], ['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022', 'Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022']]
soup = BeautifulSoup(file, 'html.parser')
blocks = soup.find_all('div', {'class': 'thumbnail offer'})
items = []
for block in blocks:
item = []
infos = block.h2.string.split(" ")
for info in infos:
if info and info != "vin:":
item.append(info)
for p in block.find_all('p'):
name, value = p.get_text().split(":")
item.append(value.strip())
items.append(item)
print(items)
[['Tesla', 'Model', 'Y', 'Long', 'Range', '2021', 'White', 'DUAL', '5YJYGDEE0MF160719', 'IAAI', '31992305', 'Stationary', 'Front End', '18388\xa0миль\xa0(Actual)', '09.02.2022'], ['Nissan', 'Leaf', 'S', '2013', 'Black', '80KW', '1N4AZ0CP9DC412799', 'IAAI', '32170717', 'Stationary', 'Mechanical', '0\xa0миль\xa0(Inoperable)', '08.02.2022'], ['Tesla', 'Model', 'S', '75D/100D/P100D', '2018', 'Black', 'U', '5YJSA1E2XJF281636', 'IAAI', '32362715', 'Stationary', 'Undercarriage', '48907\xa0миль\xa0(Actual)', '08.02.2022'], ['Tesla', 'Model', 'Y', 'Long', 'Range', '2021', 'Black', 'DUAL', '5YJYGAEE0MF293902', 'IAAI', '32286033', 'Stationary', 'Rear', '1364\xa0мили\xa0(Actual)', '08.02.2022'], ['Tesla', 'Model', '3', 'Range', 'Battery', '2018', 'Gray', 'MOTOR', '5YJ3E1EA1JF042556', 'IAAI', '32275149', 'Starts', 'Front End', '56236\xa0миль\xa0(Actual)', '08.02.2022'], ['Tesla', 'Model', '3', 'Range', 'Battery', '2018', 'White', 'MOTOR', '5YJ3E1EA7JF060592', 'IAAI', '32059234', 'Run and Drive', 'Rear', '43562\xa0мили\xa0(Actual)', '08.02.2022'], ['Mclaren', '570S', '2018', 'Yellow', '3.8L', 'SBM13FAA6JW005327', 'IAAI', '32102602', 'Run and Drive', 'Undercarriage', '19014\xa0миль\xa0(Actual)', '08.02.2022'], ['Ferrari', '458', 'Italia', 'Spider', '2015', 'Red', '4.5L', 'ZFF68NHA2F0209408', 'IAAI', '31755225', 'Stationary', 'Front End', '3270\xa0миль\xa0(Actual)', '08.02.2022'], ['Mclaren', '570S', '2018', 'Silver', '3.8L', 'SBM13FAA8JW005569', 'IAAI', '31615301', 'Stationary', 'Flood', '4677\xa0миль\xa0(Actual)', '08.02.2022'], ['Lamborghini', 'Huracan', '2017', 'Yellow', '5.2L', '10', 'ZHWUC2ZF7HLA05910', 'Copart', '66999041', 'Enhanced Vehicles', 'All Over', '0\xa0миль\xa0(Not Actual)', '07.02.2022'], ['Mclaren', 'Automotive', '600Lt', '2019', 'Orange', '3.8L', '8', 'SBM13RAAXKW007150', 'Copart', '65542851', 'Enhanced Vehicles', 'Top/Roof', '0\xa0миль\xa0(Not Actual)', '07.02.2022'], ['Ferrari', 'California', '2010', 'Red', '4.3L', 'ZFF65LJA5A0169518', 'IAAI', '32362410', 'Run and Drive', 'Right Rear', '49854\xa0мили\xa0(Actual)', '07.02.2022']]
cheking_list = [[['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'],[['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'],]
def flatten(smt_list):
if not smt_list:
return []
if isinstance(smt_list[0], list):
return flatten(smt_list[0]) + flatten(smt_list[1:])
return smt_list[:1] + flatten(smt_list[1:])
print(flatten(cheking_list))