Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
0 answers
24 views

SWIG function returning reference

I want to run SWIG on the following C++ structure : struct TestAlias { TestAlias(double a1, double a2, double a3) : angle1(a1), angle2(a2), angle3(a3) {} ...
ConanLord's user avatar
0 votes
1 answer
78 views

Is it possible to pass a python list slice as reference? [duplicate]

I was playing with python to try to reduce memory usage using various methods. One question that arose is if there's a way to pass a list slice as reference to the original list. The reason was the ...
user13079354's user avatar
0 votes
0 answers
703 views

Append DataFrame Rows In-Place Within a Function in Pandas: Elegant Solutions?

I am looking for a clear and efficient way to append rows to a DataFrame in-place within a function in pandas. Here's what I got so far: pd.concat Approach (Not In-Place): def append_rows_concat(df, ...
M. Photonicker's user avatar
-1 votes
2 answers
96 views

List modification in recursive function calls

I have two simple recursive functions in Python as follows: def test_list(outcome=[1]): outcome += [2*outcome[-1]] print(outcome) if outcome[-1] < 8: test_list(outcome) ...
Alex's user avatar
  • 11
1 vote
2 answers
77 views

Combining two lists into a list of dictionaries and all the values are the same

I have two lists I want to combine : old = ['aaa', 'bbb', 'ccc'] new = ['AAA', 'BBB', 'CCC'] and I want to make a list of dict as shown below : myList = [{'lama': 'aaa', 'baru': 'AAA'}, {'lama': 'bbb'...
mas budi's user avatar
0 votes
2 answers
81 views

How do I call multiple python functions by reference to operate on a variable so that I can change the sequence of function calls easily?

I want to create a 'function pipeline', like a factory. Let's say I have the following functions: def func1(var): var = # do something with var return var def func2(var): var = # do ...
skeetastax's user avatar
  • 1,768
-1 votes
2 answers
581 views

Why did this python list appear to get passed "by value"? [duplicate]

I defined the following function: def myFunction(a): print(f'In function, initial a = {a}, {id(a)}, {type(a)}') a = a*10 print(f'In function, final a = {a}, {id(a)}, {type(a)}') return a When ...
Kanika's user avatar
  • 1
0 votes
1 answer
39 views

Some Issues in Tree Iteration in Python while the Tree Can be Dynamically Generated on the Fly

I am writing the following functionality. A root nodes is given with 2 set of indices (_indices_lhs and _indices_rhs), and fore every index that apperas in both the left hand side and right hand side ...
Cherry Toska's user avatar
0 votes
1 answer
425 views

Sort Dictionary by Reference? (Python 3.10)

I'm attempting to sort a dictionary in Python in ascending key order. I'm trying to do this inside of a function, with the dictionary being supplied as an argument. I understand that there are mutable ...
Runsva's user avatar
  • 675
0 votes
1 answer
43 views

How to call the argument name of a constructor inside a new function?

A DecisionTreeRegressor has the callable arguments of max_depth, min_samples_split, and so on. I want to create a function that chooses which argument (feature of the tree) to call. An example: import ...
ignacM's user avatar
  • 11
0 votes
2 answers
401 views

Value of variable is not updated after passing it as a parameter into method in Python [duplicate]

Scenario: I declared a variable with value 0 in the method; Then I passed this variable as a parameter to another method which is called from first method. Nested method incremented value of the ...
Andrej Lavrinovic's user avatar
0 votes
0 answers
31 views

Deep reference ..? | Intertools.product() [duplicate]

The following (pseudo) code should insert only one ZERO per pair from itertools import product In [321]: for p in product([[1],[2]],[[4],[5]]): p[0].insert(0,0) print(p) Out [321] ([0, ...
sten's user avatar
  • 7,486
0 votes
1 answer
30 views

Linked list implementation in python issue

I have been trying to implement a linked-list in python.Any call of a variable inside a function in Python is by default call by reference.I have this code: For the list_node: class list_node: ...
Volpina's user avatar
  • 137
2 votes
1 answer
438 views

How do you pass in another object of the same type as a method parameter in python?

I am creating a class in python to represent a three-dimensional point (I know there are libraries to do this, it's more of an exercise in classes). One type of method I wish to have is one which can ...
Isaiah Blanks's user avatar
-2 votes
1 answer
38 views

Why copying lists (which are called by functions) with [:] doesn't work?

I have two lists like: prelist = [0, 0, 0, 0, 0] postlist = [50.0, 25.0, 12.5, 6.25, 3.125] I tried copying the list like so: prelist = postlist[:] but the surrounding code didn't work. When I copy ...
Emre Sagbas's user avatar

15 30 50 per page
1
2 3 4 5
20