0
Good afternoon!
I have a problem and need help, I am working with 3 distinct lists that should be added to a dictionary, but so I can capture all values without one overwriting the other, I need to concatenate these 3 lists. I know that using ex: list1.extend(list2)
, I can concatenate, but I don’t know if the same applies to concatenation of multiple lists, is there any other way to accomplish this concatenation? Follows code structure, already showing the dictionary.
arrayDisciplinas = []
if response.xpath('//*[contains(a,"PDL")]//following-sibling::div//text()[not(re:test(.,"^\s+$"))]').extract() is not None:
for linha in response.xpath('//*[contains(a,"PDL")]//following-sibling::div//text()[not(re:test(.,"^\s+$"))]').extract():
disc = Disciplina()
disc.set_all()
if linha is not None:
disc['Nome'] = linha.encode('utf-8')
arrayDisciplinas.append(dict(disc))
if len(arrayDisciplinas) > 0:
disciplina = arrayDisciplinas
arrayDisciplinas2 = []
if response.xpath('//*[contains(a,"CLEO ESP")]//following-sibling::div//text()[not(re:test(.,"^\s+$"))]').extract() is not None:
for linha in response.xpath('//*[contains(a,"CLEO ESP")]//following-sibling::div//text()[not(re:test(.,"^\s+$"))]').extract():
disc2 = Disciplina()
disc2.set_all()
if linha is not None:
disc2['Nome'] = linha.encode('utf-8')
arrayDisciplinas2.append(dict(disc2))
if len(arrayDisciplinas) > 0:
disciplina2 = arrayDisciplinas2
arrayDisciplinas3 = []
if response.xpath('//*[contains(a,"CLEO ESTRUTURANTE")]//following-sibling::div//text()[not(re:test(.,"^\s+$"))]').extract() is not None:
for linha in response.xpath('//*[contains(a,"CLEO ESTRUTURANTE")]//following-sibling::div//text()[not(re:test(.,"^\s+$"))]').extract():
disc3 = Disciplina()
disc3.set_all()
if linha is not None:
disc3['Nome'] = linha.encode('utf-8')
arrayDisciplinas3.append(dict(disc3))
if len(arrayDisciplinas) > 0:
disciplina3 = arrayDisciplinas3
disciplina.extend(disciplina2)
item['Disciplinas'] = disciplina3
Thank you so much for your help, really the best situation for my case was using form 2, following the tutorial of Gustavorps :).
– Jonathan Igor Bockorny Pereira