Currently I am learning Python (not programming) and I am trying to solve my first problem with this language.
First of all I have checked what is the difference between import X
and from X import Y
. I know that the first load into the namespace the package but not the methods of this package, so you need to write X.Y, on the other hand the second import way load into the namespace the function and the reference to the package. Despite this I do not understand why import math.sqrt
fails. I get this error: math is not a package
.
Does anybody knows what happens?
Then I am trying how is write this statement:
sum([
pow(dic1[elem]βdic2[elem], 2)
for elem in dic1 if elem in dic2
])
As I told before I know programming and I understand what it is doing, but it seems a bit illogical for me because seems that python reads the script in different direction than the "typical" languages.
If I am not wrong this statement sum all the differences between elements in both dictionaries (powered 2) but only do the sum if it does the for statement which is conditioned that in dic2 exists elem.
Is this correct?
Thank you!