I wrote this little python function to reverse speedwalk strings of the form:
4we3(sw)2(up)3e(in)(down)(out)(ne)
It handles e,w,s,n,ne,se,nw,sw,up,down,in and out. It doesn't handle other nonstandard directions. It's not the most efficient code, but it works for me.
4we3(sw)2(up)3e(in)(down)(out)(ne)
It handles e,w,s,n,ne,se,nw,sw,up,down,in and out. It doesn't handle other nonstandard directions. It's not the most efficient code, but it works for me.
import string
def reverseSpeedWalkStr(str):
str=str.lower()
#remove whitespace
strippedstr=''
for eachchar in str:
if eachchar != " ":
strippedstr=strippedstr+eachchar
#add spaces between commands
spacedstr=strippedstr.replace("(sw)","(SW) ")
spacedstr=spacedstr.replace("(se)","(SE) ")
spacedstr=spacedstr.replace("(nw)","(NW) ")
spacedstr=spacedstr.replace("(ne)","(NE) ")
spacedstr=spacedstr.replace("(up)","(UP) ")
spacedstr=spacedstr.replace("(down)","(DOWN) ")
spacedstr=spacedstr.replace("(in)","(OUT) ")
spacedstr=spacedstr.replace("w","W ")
spcadedstr=spacedstr.replace("e","E ")
spacedstr=spacedstr.replace("s","S ")
spacedstr=spacedstr.replace("n","N ")
#reverse order of commands
strlist=spacedstr.split()
strlist.reverse()
reversedstr=string.join(strlist)+' '
#swap direction
swappedstr=reversedstr.replace("(NE) ","(SW)")
swappedstr=swappedstr.replace("(NW) ","(SE)")
swappedstr=swappedstr.replace("(SE) ","(NW)")
swappedstr=swappedstr.replace("(SW) ","(NE)")
swappedstr=swappedstr.replace("(DOWN) ","(UP)")
swappedstr=swappedstr.replace("(UP) ","(DOWN)")
swappedstr=swappedstr.replace("(OUT) ","(IN)")
swappedstr=swappedstr.replace("W ","e")
swappedstr=swappedstr.replace("E ","w")
swappedstr=swappedstr.replace("S ","n")
swappedstr=swappedstr.replace("N ","s")
swappedstr=swappedstr.lower()
return(swappedstr)