Questions tagged [argument-unpacking]

Use this tag for questions related with argument unpacking, a technique that allows Arrays and Traversable objects to be extracted/unpacked into argument lists/sequences.

is usually found in PHP, Python and Go.

144 questions
0
votes
0 answers

Input each element of a list into a function in python

Suppose I have a list l=[A,B,C,D] and a pre-defined funcion (I am using sympy.solve_linear_system(matrix,A,B,C,D). I want to evaluate the function without writing in A,B,C,D. I want to do it in terms of the list. Is this possible? When I use Unpack…
0
votes
1 answer

Does * Unpacking Use Memory on Generator Expression?

Example for context: Does calling * to unpack input put everything into memory? I'm hoping not but just want to confirm my understanding. input = (x for x in ((1, 'abc'), (2, 'def'))) # generator expression unzipped = zip(*input) # Does *input get…
0
votes
0 answers

How to print unpacked iterable or string?

I am trying to print a unpacked iterable, or a string if said iterable is empty in Python 3.9 (also happens in 3.10), and I am getting some unexpected behavior. print is applying the star operator to the whole Iterable or str expression, regardless…
0
votes
1 answer

Passing a dictionary to a function with unpacking argument

This below snippet of code gives me this error TypeError: pop() argument after ** must be a mapping, not tuple. class a(): data={'a':'aaa','b':'bbb','c':'ccc'} def pop(self, key, **args): return self.data.pop(key,…
Kumar
  • 949
  • 1
  • 13
  • 23
0
votes
1 answer

Printing a tuple in Python using both "for" loop and unpacking with star operator (*)

I am trying to print the items of the "result" tuple in the following code in 2 different ways: using a "for" loop using a star operator in the print() method In the output, the string "reference point" is supposed to separate the results of the…
Marios
  • 3
  • 2
0
votes
2 answers

How to make it one-liner? Convert list to a bunch of parameters

I have the following code: from datetime import datetime ds = "2020.10.10.12.30.59" y, M, d, h, m, s = [int(x) for x in ds.split('.')] dt = datetime(y, M, d, h, m, s) print(dt) I would like to make it to one-liner something like this: dt =…
pvoj
  • 339
  • 3
  • 14
0
votes
1 answer

how to pack my numpy variables and arrays when calling curve_fit?

This is my standalone code to reproduce the problem: import numpy as np from scipy.optimize import curve_fit def find_vector_of_minor_axis_from_chunk(data): n = 20 # number of points time = np.linspace(0, 2 * np.pi, n) …
Andreas Schuldei
  • 343
  • 1
  • 15
0
votes
1 answer

Typescript unpacking arguments to overloaded function

Just to illustrate what I mean by "unpacking", consider the following example function simpleFunc(a: number, b: string): void { /* ... */ } function simpleProxy(args: [number, string]) { simpleFunc(...args) } This works just fine, with…
Antoine
  • 13,494
  • 6
  • 40
  • 52
0
votes
1 answer

not enough values to unpack (expected 2, got 1) adaboost algorithm

def adaboost(X_train, Y_train, X_test, Y_test, lamb=0.01, num_iterations=200, learning_rate=0.001): label_train = 2*Y_train -1 label_test = 2*Y_test -1 [n,p] = X_train.shape [ntest, ptest] = X_test.shape X_train_1 =…
Rad
  • 7
  • 6
0
votes
2 answers

A Python function that interleaves arbitrary number of lists as parameters

Edited for the sake of simplicity, as I have pin pointed the issue to 'argument unpacking'. I am trying to write a function that interleaves an arbitrary number of lists as parameters. All the lists have equal length. The function should return one…
Saurus
  • 79
  • 1
  • 7
0
votes
1 answer

Packing keyword arguments in Racket?

Is there a way to specify keyword arguments to a function as a dictionary, analogously to the . that allows us to supply a list for positional arguments? I'm looking for something analogous to python's *args and **kwargs. In more detail: If we want…
mindthief
  • 12,755
  • 14
  • 57
  • 61
0
votes
1 answer

Invalid unpacking arguments

I was reading an online document explaining unpacking (*args and **kwargs). Getting confused by the following two asserts, not sure why the second function is invalid. Could anyone help me to understand the reason? def f(x, y, z): return [x, y,…
r0n9
  • 2,505
  • 1
  • 29
  • 43
0
votes
1 answer

Unpacking Python Dictionary of Various Length into sql query

I currently have a function which takes a dictionary as an input and returns all columns in database table as a dict: import sqlite3 def get_person_dict_from_dict(self): database = "/Users/Mary/Documents/Database/{DB}.db".format(DB=self['db']) …
Mary
  • 788
  • 6
  • 19
  • 43
0
votes
1 answer

Unpacking set in string format in python only returns first value

I have converted a DataFrame Column into a set, and I am trying to format the values into a string using the * to unpack it like a list. However, it only returns the first value. I am using the python-docx to automatically create reports based on…
0
votes
1 answer

Specifying arguments in a function from a list

I've read up on a number of threads (here and here) and the docs (here and here). However, I can't get this to work. I get an error of AxisError: axis 0 is out of bounds for array of dimension 0 Thanks. import pandas as pd from scipy.stats import…
June
  • 720
  • 10
  • 22