I’m coding in python and I want to change the mapping of my characters so that if the same character is printed again the value of it changes to 1 and another value takes the value of the initial place.
My code so far is:
def custom_mapping(hex_string):
# Define the custom mapping here
char_to_number = {
'0': 3,
'1': 1,
'2': 4,
'3': 2,
'4': 5,
'5': 12,
'6': 6,
'7': 7,
'8': 8,
'9': 9,
'a': 10,
'b': 11,
'c': 15,
'd': 13,
'e': 14,
'f': 0
}
sorted_chars = sorted(hex_string, key=lambda char: char_to_number[char])
return ''.join(sorted_chars)
I want to change keep the value of f at 0 the first time it’s seen and then change it to 9 while 9 becomes 0. This is the problem I’m having. I want to do this with an if statement not a for loop because a for loop will take time to load and the rest of my code works in a way where everything needs to be instant.
Frank Eichmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.