Posts by Daniel Reis • 356 points
6 posts
-
2
votes3
answers4285
viewsA: Use of colon character ":" in Python
The character : indicates that we will start a subblock of code. The equivalent of { in Javascript and Java. Next lines must be indented. It is used in function statements def, class, instructions…
-
0
votes3
answers4053
viewsA: How to add list values in tuples?
One-line solution, no use import nor for: >>> sum([b[0] for a, b in x]), sum([b[1] for a,b in x]) (9, 12) Version that returns a list: >>> [sum([b[0] for a, b in x]), sum([b[1] for…
-
2
votes2
answers531
viewsA: python packages with dependency installation
In his setup.py I’m sure you’re using a function setup() of settuptools. It shall include in that function the argument install_requires with the list of dependencies. For example: setup(…
pythonanswered Daniel Reis 356 -
1
votes2
answers453
viewsA: Make list changes to be local in Python?
To make local changes to a list passed in an argument, you need to work on a copy of it. x_local = list(x) x_local[1] = 'Novo valor'
pythonanswered Daniel Reis 356 -
1
votes4
answers11584
viewsA: How to put a Python module in a different folder than my script?
Why not use a symlink for pasta2 within the pasta1: $ ln -s ./pasta2 ./pasta1/pasta2
-
18
votes3
answers1094
viewsQ: Assign value to a dictionary variable that is optional
I have a function where one of the parameters is a dictionary, but it’s optional. I need to assign a value in this dictionary, but take into account the case where this parameter is not filled in.…