Skip to content
Advertisement

Reverse the strings in the column relative to the characters in the middle of the string

I have a column of phone numbers. How can I flip them with regards to the two digits in the middle.

# The original column
[["00-07-16"],
 ["23-27-21"],
 ["01-12-16"]]
# The reversed column
[["16-07-00"],
 ["21-27-23"],
 ["16-12-01"]]

Advertisement

Answer

You could use this function to reverse each number :

def rev(num:str):
    return num[6:8] + num[2:6] + num[0:2]
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement