0

I have a list that looks like:

[['a', 'b', 'null', 'c'], ['d', 'e', '5', 'f'], ['g' ,'h', 'null' ,'I'] ]

I want to uppercase all strings, but when I try:

x = 0
for row in range(1, sheet.nrows):
    listx.append(sheet.cell(row, x))
    [x.upper() for x in x in listx]
x += 1

I got:

TypeError: 'bool' object is not iterable

How can I make a statement for it?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

2 Answers2

3

This list comprehension does it, and retains your list of lists structure:

listx = [['a', 'b', 'null', 'c'], ['d', 'e', '5', 'f'], ['g' ,'h', 'null' ,'I'] ]

[[x.upper() for x in sublist] for sublist in listx]

returns:

[['A', 'B', 'NULL', 'C'], ['D', 'E', '5', 'F'], ['G', 'H', 'NULL', 'I']]
sacuL
  • 49,704
  • 8
  • 81
  • 106
1

is this what you're looking for:

l = [['a', 'b', 'null', 'c'], ['d', 'e', '5', 'f'], ['g' ,'h', 'null' ,'I']]
new_list = []
for row in l:
    new_list.append([x.upper() for x in row])
gyx-hh
  • 1,421
  • 1
  • 10
  • 15