Skip to content

Instantly share code, notes, and snippets.

@andscoop
Created October 19, 2017 14:57
Show Gist options
  • Save andscoop/38bfa6156bc3335cec995643c198358c to your computer and use it in GitHub Desktop.
Save andscoop/38bfa6156bc3335cec995643c198358c to your computer and use it in GitHub Desktop.
Should I loop or use is this list comphrension easier to read?
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