If I understand your question well, you want to split the elements of the list listing_jobs
by \n
? if so, you can use list comprehension as follows:
d = ['Senior Cloud Specialist\nFull-time · Singapore · 5 - 10 Years\n12 days ago',
'Cloud Native Developer\nFull-time · Hyderabad · 2 - 5 Years\n13 days ago']
d = [x.strip().split("\n") for x in d]
That will give the following list of lists:
[['Senior Cloud Specialist',
'Full-time . Singapore . 5 - 10 Years',
'12 days ago'],
['Cloud Native Developer',
'Full-time . Hyderabad . 2 - 5 Years',
'13 days ago']]
But you will end up with a list of lists. If you want to flatten it to a list of strings, do the following:
result = []
for el in d:
result = result + el
output:
['Senior Cloud Specialist',
'Full-time . Singapore . 5 - 10 Years',
'12 days ago',
'Cloud Native Developer',
'Full-time . Hyderabad . 2 - 5 Years',
'13 days ago']
Overall code:
# original data
d = ['Senior Cloud Specialist\nFull-time · Singapore · 5 - 10 Years\n12 days ago',
'Cloud Native Developer\nFull-time · Hyderabad · 2 - 5 Years\n13 days ago']
# split by "\n"
d = [x.strip().split("\n") for x in d]
# flatten the list of lists into a list of strings
result = []
for el in d:
result = result + el
Why you have the following error?
"AttributeError: 'list' object has no attribute 'strip'"
Because strip can be applied on str
(string) type and you are applying it on a list.