Context: I'd like to specify the names of a bunch of directories that I want my script to make. I'd like to declare these path names as variables and add them to a list, which I will iterate over to make the directories. Python 2.7.5.
I'm trying the following:
dir_list = [
(dir_1 = "<path_to_dir_1>")
(dir_2 = "<path_to_dir_2>")
]
And I get:
(dir_1 = "<path_to_dir_1>"),
^
SyntaxError: invalid syntax
If I do:
dir_1 = "<path_to_dir_1>"
dir_2 = "<path_to_dir_2>"
dir_list = [dir_1, dir_2]
print dir_list
It works fine without an error.
I have searched and did not find an answer to this question, though I did find an answer to how to format multi-line dictionaries in Python: What is the proper way to format a multi-line dict in Python?
And the PEP8 style-guide offers guidance on how to format multi-line lists as well: https://www.python.org/dev/peps/pep-0008/#indentation
However, I have not found an answer to whether I can collapse variable assignment and list inclusion into one step.