Subtracting a scalar from a list in Python using the mathematical operator -
resulting in a new list. The scalar value is subtracted from each element of the list individually. Here is an example:
main.py99 chars5 lines
Output:
main.py20 chars2 lines
In the above example, we subtracted 5 from each element of the list my_list
and stored the result in new_list
.
gistlibby LogSnag