Posts by Renan • 371 points
5 posts
-
0
votes2
answers2151
viewsA: How to avoid "Missing 1 required positional argument" error when one of the parameters is omitted
Using arguments with default values may be what you want: def f(v1=None, v2=None): if v1: print(v1) if v2: print(v2) So if you don’t pass v2, it’s None and therefore if v2 is fake, not running the…
-
0
votes1
answer297
viewsQ: Return value from inside fetch
I’m trying to read a local Javascript file and put your data into a variable and so far I’ve written the following code: function fetchDictionary() { const URL_TO_FETCH = './lang-portuguese.txt';…
-
9
votes1
answer4345
viewsQ: How to sort a list of tuples by the nth element?
I have a list of fashion tuples: [(0, 1), (2, 3), (4, -5), (6, -3)] I want to sort that list by the second value of each tuple (i.e., in case we would [(4, -5), (6, -3), (0, 1), (2, 3)]. How to do…
-
12
votes1
answer4345
viewsA: How to sort a list of tuples by the nth element?
The simplest way is to use key in the call to method sort of the list: data = [(0, 1), (2, 3), (4, -5), (6, -3)] data.sort(key=lambda x: x[1]) >>> data [(4, -5), (6, -3), (0, 1), (2, 3)]…
-
5
votes1
answer4590
viewsQ: How to resize graphics in Ipython Notebook without loss of quality?
In Ipython Notebook I produce graphics with (for example): x = [1,2,3,4] y = [5,6,7,8] plot(x, y) When I place the cursor over the generated graph, the tool appears at the bottom right corner to…