Suppose I have the following list:
l = ['the quick fox', 'the', 'the quick']
I would like to convert each list item to url as follows:
['<a href="http://url.com/the">the</a>', '<a href="http://url.com/quick">quick</a>','<a href="http://url.com/fox">fox</a>', '<a href="http://url.com/the">the</a>','<a href="http://url.com/the">the</a>', '<a href="http://url.com/quick">quick</a>']
So far I have tried the following:
list_words = ['<a href="http://url.com/{}">{}</a>'.format(a, a) for a in x[0].split(' ')]
The problem is that the above list comprehension just does the job for the first element of the list:
['<a href="http://url.com/the">the</a>',
'<a href="http://url.com/quick">quick</a>',
'<a href="http://url.com/fox">fox</a>']
I also tried with map, but this did not work:
[map('<a href="http://url.com/{}">{}</a>'.format(a,a),x) for a in x[0].split(', ')]
Any idea on how to create such links from offer list tokens?