Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:10:39+00:00 2026-05-31T05:10:39+00:00

Is it possible to write a function f that takes an arbitrary tuple of

  • 0

Is it possible to write a function f that takes an arbitrary tuple of mixed data:

T = 1.0
N = 20
L = 10
args = (T,N,L)

f(*args) # or maybe f(T,N,L)?

and returns as output:

{'T':1.0, 'N':20, 'L':10}

There is a related question using local, but I seem to lose the names once they are passed to the function. Is there a way to prevent this? I’m guessing that the variables are being passed by value and thus they are considered new objects.

Followup: Python: Using a dummy class to pass variable names?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:10:40+00:00Added an answer on May 31, 2026 at 5:10 am

    No, this is not possible in general with *args. You’ll have to use keyword arguments:

    >>> def f(**kwargs):
    ...  return kwargs
    ... 
    >>> f(T=1.0, N=20, L=10)
    {'T': 1.0, 'L': 10, 'N': 20}
    

    The reason is that *args does not introduce names for the individual arguments; it only introduces the name args for the whole list of them. The function has no insight into how what names, if any, the arguments have outside of it.

    When the number of arguments is fixed, you can do this with locals:

    >>> def g(T, N, L):
    ...  return locals()
    ... 
    >>> g(T=1.0, N=20, L=10)
    {'L': 10, 'T': 1.0, 'N': 20}
    

    (or explicitly with return {'T': T, 'N': N, 'L': L}.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to write a function that takes a type and returns a
Is it possible to write a C function that does the following? Allocate a
How do I write a function in C++ that takes a string s and
I want to write a Module Arg[f_,n_] that takes a function f (having <=n
I try to write a class that takes a tuple of functions as its
I'm looking to write a function that takes the integers within a list, such
Is it possible to write a Hadoop-ready reduce function that can find the longest
A while back I found that it's possible to write a C++ function that
I need to write a function that takes 4 bytes as input, performs a
Is it possible to write a c++ template function which takes a variable number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.