0

Ok, so I have this list,

[['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I']]

I want to add html tags to the values in the inner lists.

How would I go about doing this?

i.e.

[['<b>A</b>', '<b>B</b>', '<b>C</b>'], ['<b>D</b>', '<b>E</b>', '<b>F</b>'], ['<b>G</b>', '<b>H</b>', '<b>I</b>']]
Steven Matthews
  • 9,705
  • 45
  • 126
  • 232

3 Answers3

5
[['<b>%s</b>' % x for x in data] for data in my_list]
JBernardo
  • 32,262
  • 10
  • 90
  • 115
1

Like this?

def AddHtml(s): return '<b>' + s + '</b>'

def AddHtmlArray(a) : return map(AddHtml, a)

...

map(AddHtmlArray, yourList)
Ry-
  • 218,210
  • 55
  • 464
  • 476
1
>>> l = [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I']]

>>> out = [['<b>'+s+'</b>' for s in subl] for subl in l]

>>> out
[['<b>A</b>', '<b>B</b>', '<b>C</b>'], ['<b>D</b>', '<b>E</b>', '<b>F</b>'], ['<b>G</b>', '<b>H</b>', '<b>I</b>']]
Aphex
  • 7,390
  • 5
  • 33
  • 54