Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Write a Nested For Loop in One Line Python with File Url and File Name

 data = json.dumps({'conf':{a:b for a in table_name for b in file_url}})
 print(data)

I have 2 files in file_url.

sales_dy_20221022.csv
sales_wk_20221022

I have 2 table names in table_name

sales_dy
sales_wk

If I write the code like the above I get the result below.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"conf": {
"sales_dy": "sales_dy_20221022.csv",
"sales_wk": "sales_dy_20221022.csv"
}

How can I change the code and get the result below?

"conf": { "sales_dy": "sales_dy_20221022.csv", "sales_wk": "sales_wk_20221022.csv" }

>Solution :

You are in the right path, use zip.
ex. data = json.dumps({'conf':{a:b for a,b in zip(table_name,file_url)}})

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading