0

I want to replace all second elements of the lists in my 2d list with "ele2".

eleli = [['ele', 'ele', 'ele', 'ele', 'ele'], ['ele', 'ele', 'ele', 'ele', 'ele'], ['ele', 'ele', 'ele', 'ele', 'ele']]

rep = "ele2"

last = []
for e in eleli:
    ere = e.replace(e[0][1], rep)
    last += ere

print(last)

AttributeError: 'list' object has no attribute 'replace'

I tried the above, but an error occurred. the result i want is

>>>[['ele', 'ele2', 'ele', 'ele', 'ele'], ['ele', 'ele2', 'ele', 'ele', 'ele'], ['ele', 'ele2', 'ele', 'ele', 'ele']]

I've been searching for a way, but couldn't find a completely matching answer. help

anfwkdrn
  • 327
  • 1
  • 7

0 Answers0