Linked Questions
19 questions linked to/from What is the pythonic way to unpack tuples as function arguments?
578 votes
5 answers
380k views
Expanding tuples into arguments
Suppose I have a function like: def myfun(a, b, c): return (a * 2, b + c, c + b) Given a tuple some_tuple = (1, "foo", "bar"), how would I use some_tuple to call myfun? This ...
12 votes
2 answers
13k views
Python 3 - using tuples in str.format() [duplicate]
I'm trying to use the str.format() method, and having some difficulties when my values are stored within a tuple. For example, if I do: s = "x{}y{}z{}" s.format(1,2,3) Then I get 'x1y2z3' - no ...
285 votes
3 answers
256k views
Pass a list to a function to act as multiple arguments [duplicate]
In a function that expects a list of items, how can I pass a Python list item without getting an error? my_list = ['red', 'blue', 'orange'] function_that_needs_strings('red', 'blue', 'orange') # works!...
36 votes
6 answers
51k views
Creating a list in Python with multiple copies of a given object in a single line
Suppose I have a given Object (a string "a", a number - let's say 0, or a list ['x','y'] ) I'd like to create list containing many copies of this object, but without using a for loop: L = ["a", "a", ...
20 votes
3 answers
113k views
IndexError: Replacement index 1 out of range for positional args tuple
I am following a tutorial and I don't know why I got this error: <ipython-input-61-d59f7a5a07ab> in extract_featuresets(ticker) 2 tickers, df = process_data_for_labels(ticker) ...
4 votes
4 answers
2k views
Using tuples with .format in python
while using the .format() with text filling, I encounter this error. what I have: tuple = ('a', 'b', 'c') text = "Hi {} hello {} ola {}" #command I tried to run text.format(tuple) The output I am ...
1 vote
2 answers
8k views
python: ctypes, read POINTER(c_char) in python
I have a ctypes field that is a POINTER(c_char) (it had to be, per the documentation, c_char_p didn't work for my application: https://docs.python.org/3.7/library/ctypes.html#ctypes.c_char_p) For a ...
3 votes
1 answer
6k views
Extract columns using "genfromtxt"
I've already read these 2 questions before asking this one (q1 and q2) but I haven't found any satisfying answer I need to extract two columns from a 2D-array without using pandas or loadtxt, but ...
2 votes
2 answers
2k views
How to 'unpack' a list or tuple in Python
I'm writing a Python program to play Tic Tac Toe, using Numpy arrays with "X" represented by 1 and "O" by 0. The class includes a function to place a mark on the board: import numpy as np class ...
3 votes
1 answer
3k views
Tuple unpacking in R
Python has the *(...) syntactic sugar. Can you do this in R? t = (2010, 10, 2, 11, 4, 0, 2, 41, 0) dt = datetime.datetime(*t[0:7]) From here: https://stackoverflow.com/a/2238361/1007926 This allows ...
-1 votes
3 answers
358 views
Returning positional arguments from a function [duplicate]
The class( people ) requires 3 arguments called "name, middle_name and surname" and I am trying to give these arguments like down below: def argument(): name = input("name : ") ...
3 votes
1 answer
3k views
Pandas dataframe of tuples?
I have a pandas dataframe that I create from a list (which is created from a spark rdd) by calling: newRdd = rdd.map(lambda row: Row(row.__fields__ + ["tag"])(row + (tagScripts(row), ))).collect() ...
0 votes
2 answers
826 views
Can I run multiple Ipython qt console in the same time?
This should be extremely simple to people who know this, but I am not one of them. I searched a lot about multi-processing, but it makes me even more confused... I need to process about 160 data ...
1 vote
1 answer
1k views
Networkx Python Edges Comparison
I have been trying to build a graph for a project and I have been trying to identify newly added edges after populating it with more information. For instance below you can see its first and second ...
-1 votes
5 answers
115 views
How can I dynamically create the output of the following code?
from tkinter import * height = 600 width = 600 root = Tk() canvas = Canvas(root, width = width, height = height, bg = 'red3') canvas.pack() # Code for Fries canvas.create_polygon(150, 100, 160, 250, ...