Created
October 19, 2017 14:57
-
-
Save andscoop/38bfa6156bc3335cec995643c198358c to your computer and use it in GitHub Desktop.
Should I loop or use is this list comphrension easier to read?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_path(self, field_path): | |
base = "\"${}\"" | |
# Create a template for each value in array | |
# reasonable assume iether str or int will be passed | |
tmplts = ["['{}']" if isinstance(path, str) else "[{}]" for path in field_path ] | |
paths = [tmplts[i].format(field_path[i]) for i in range(len(field_path))] | |
full_path = ''.join(paths) | |
return base.format(full_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment