Good day to all.
I've been looking for a way to replace items within an array.
Basically I have an array with nested list that looks like that:
array = [ ('a', 'a'), 'c', ('c', 'a'), 'g', 'g', ('h', 'a'), 'a']
Now I'm looking for a way to replace all the appearances of 'a' with 'z'.
and I was hopping to use the following code line in order to achieve that:
new_array = [w.replace('a', 'z') for w in array]
new_array = [ ('z', 'z'), 'c', ('c', 'z'), 'g', 'g', ('h', 'z'), 'a']
Yet, unfortunately I'm receiving the following error:
AttributeError: 'tuple' object has no attribute 'replace'.
I understand the main problem is caused by the use of the tuple (a, x), but they're crucial part of the desired array.
I've spent hours looking for a way around it, And I would highly appreciate any hint in the right direction.
Your help is appreciated!