
Making Python simple for you, by exploring the fundamentals. Tips and explanations to become code-literate in this AI age. Building @PythonResources
Maximize your coding skills 馃憞
Joined May 2019
- Tweets13.6K
- Following104
- Followers8.9K
- Likes9K
Replying to @PythonPr
Answer: B
Solution: x and y are sets.
What does the `-` do on sets?
It computes the "set difference".
The diagram makes it clear (credit in description):
The shaded region is the part of A which is not in B.
That is the set difference.
+
Replying to @PythonPr
Answer: A
Solution: a and b are sets.
The code computes
a ^ b
What is this operator ^?
The operator's action is called Symmetric Difference.
The diagram shows it the symmetric difference of A and B as shaded:
+
Replying to @CodingComputing @PythonPr
In Python there is a module called `decimal` which has you covered.
It is designed specially for exactly representing decimal numbers.
There you won't have such problems.
See image for demo. I hope this answer was helpful!
Replying to @CodingComputing @PythonPr
You can count backwards from the rightmost item.
The 2nd-last is at index -2,
the 3rd-last at -3, and so on.
See image:
Applying to this question
+
Replying to @CodingComputing @PythonPr
BONUS quick summary of how to decompose a list comp:
`extend` and `append` are both list methods that seem similar
But don't confuse `extend` with `append`
`append` just adds the argument as one item to the list
`extend` unpacks the iterable and adds each item
See image for example:












