Write an algorithm for the network administrator to help him find number of data characters that do not change position even after the data stream is reversed
#The algorithm is very simple and it is clearly demostrated below using an example
myString = 'adadda' #Using this set of characters as an example
data = list(myString) #Putting the characters in a list
string_reversed = list(reversed(myString)) #Reversing the list and storing it in a variables
st = "" #A string to store the characters that do not change the position
for row in string_reversed: #Iterating over the original characters
for i in data: #Iterating over the characters after reversal
#Checking if the position of character has not changed
if string_reversed.index(row) == data.index(row):
st += i
print(set(list(st))) #Printing the final list of characters that do not change the position
Comments
Leave a comment