I have this code to change directory information in python. I'd like to change '/a/b/c' into '/x/b/c'.
import os x = "/a/b/c" y = x.split(os.sep) y[1] = 'x' os.sep.join(y) Now I just want to know if python can make it one-liner. I can't simply use os.sep.join(x.split(os.sep)[1] = 'x') as it causes an syntax error. What might be other options in python?