Skip to content
Advertisement

Dividing each corresponding element of two lists in Python

I have two lists in seperate text files and I need to divide each value by the corresponding value in the other list. The following is a smaal bit of the data from both files:

JavaScript

I have opened both lists like this:

JavaScript

I presume I have to use the proper loop to divide both lists but I haven’t managed to get it done yet.

Advertisement

Answer

A readable, clean and safe way of doing this would be:

JavaScript

If you want to store it in a list:

JavaScript

If you want to write to another file, you can either iterate over result list and write to file, or:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement