please help me with this python exercise
Question:
input = [[0,1,2,3,4,5], [0,1,2,3,4,5], [0,1,2,3,4,5]]
output = [0****0, *1**1*, **22**]
This is what I’ve tried so far:
for x in input:
for y in x:
if int(x.index(y)) == int(input.index(x)):
And I got stuck. I don’t know how to make the value of the [0] index == that of the last index (and the [1] index == the [-2] index and so on) and then change the rest into ‘*’
Answers:
inp = [[0,1,2,3,4,5], [0,1,2,3,4,5], [0,1,2,3,4,5]]
# out = [0****0, *1**1*, **22**]
out = [] # here we create a list for finale output, now it's empty
count = 0 #this variable count we use for knowing what is the index iterable element
for i in inp: # ordinary for loop, we eterate inp. on first iteration i == inp[0], on sec i == inp[1], etc
s = list('*'*len(i)) #the same as as_digit(lengh of element i ) times '*'. like ['*','*','*','*','*','*',]
s[count] = str(i[count]) #here we change list s by index count. it's to equal index count from i
s[-(count+1)] = str(i[count]) #the same action but from right side
out.append(''.join(s)) #''.join(s) makes list s into just string, out.append() append to out
count+=1 #each eteration we +1 to count for knowing the index of i in inp during next iteration
print(out) #['0****0', '*1**1*', '**22**']
input = [[0,1,2,3,4,5], [0,1,2,3,4,5], [0,1,2,3,4,5]]
output = [0****0, *1**1*, **22**]
This is what I’ve tried so far:
for x in input:
for y in x:
if int(x.index(y)) == int(input.index(x)):
And I got stuck. I don’t know how to make the value of the [0] index == that of the last index (and the [1] index == the [-2] index and so on) and then change the rest into ‘*’
inp = [[0,1,2,3,4,5], [0,1,2,3,4,5], [0,1,2,3,4,5]]
# out = [0****0, *1**1*, **22**]
out = [] # here we create a list for finale output, now it's empty
count = 0 #this variable count we use for knowing what is the index iterable element
for i in inp: # ordinary for loop, we eterate inp. on first iteration i == inp[0], on sec i == inp[1], etc
s = list('*'*len(i)) #the same as as_digit(lengh of element i ) times '*'. like ['*','*','*','*','*','*',]
s[count] = str(i[count]) #here we change list s by index count. it's to equal index count from i
s[-(count+1)] = str(i[count]) #the same action but from right side
out.append(''.join(s)) #''.join(s) makes list s into just string, out.append() append to out
count+=1 #each eteration we +1 to count for knowing the index of i in inp during next iteration
print(out) #['0****0', '*1**1*', '**22**']