I try to use 'uga'
as input(=text). I want to get [['U','g','a'],['u','G','a'],['u','g','A']
as output.
I have tried this code :
text = 'uga'
abc = list(text)
out_list = []
for i in range (len(text)):
out_list.append(abc)
x = out_list.copy()
for item in range(len(x)):
x[item][item] = x[item][item].upper()
print(x)
after using that code I got [['U', 'G', 'A'], ['U', 'G', 'A'], ['U', 'G', 'A']]
as the output.
If we cut the code...
text = 'uga'
abc = list(text)
out_list = []
for i in range (len(text)):
out_list.append(abc)
x = out_list.copy()
print(x)
it will give [['u', 'g', 'a'], ['u', 'g', 'a'], ['u', 'g', 'a']]
as the output.
after that I try to make the code without append()
. I just make a new variable using this list --> [['u', 'g', 'a'], ['u', 'g', 'a'], ['u', 'g', 'a']]
which is same as x
a = [['u', 'g', 'a'], ['u', 'g', 'a'], ['u', 'g', 'a']]
for item in range(len(a)):
a[item][item] = a[item][item].upper()
print(a)
surprisingly I can get result which is [['U', 'g', 'a'], ['u', 'G', 'a'], ['u', 'g', 'A']]
after that I try again using append but manually, like this:
b = []
b.append(['u','g','a'])
b.append(['u','g','a'])
b.append(['u','g','a'])
for i in range (len(b)):
b[i][i] = b[i][i].upper()
print(b)
the result is right too which is [['U', 'g', 'a'], ['u', 'G', 'a'], ['u', 'g', 'A']]
I don't know why my first code give the wrong result... because when I check the type of x
, a
, and b
it same which is a list.
After that I check a==b==x
it gives the result True
I also put them in the same code which is:
for i in range (len(something)):
something[i][i] = something[i][i].upper()
I have thinking a lot and ask many of friends, but no body could know what happened..
I'm sorry because my English is not very good. Hope you could help me...
Thank you