Answer the question
In order to leave comments, you need to log in
Python list to csv, how to write correctly?
I parse the project, I take 2 parameters: Breadcrumbs and the name of the product.
I save in csv. The write data looks like this:
['home', '', 'Semiconductors', 'Analog', 'System Management', 'Voltage Detectors'], ON Semiconductor | NC7SB3157P6X
Semiconductors > Analog > System Management > Voltage Detectors
Answer the question
In order to leave comments, you need to log in
At the input you have crumbs in the form of a list of strings, apparently.
* remove the first paragraph
* remove empty elements
* format with "angle bracket" delimiter
To form terms from a list, you can use the list comprehension:
lst = ['home', '', 'Semiconductors', 'Analog', 'System Management', 'Voltage Detectors']
# здесь мы проходим по списку
# добавляем в результирующую строку
# только если строка не является первым элементом списка и имеет ненулевую длину
result = ' > '.join([x for x in lst if (len(x) and x != lst[0])])
print(result) # Semiconductors > Analog > System Management > Voltage Detectors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question