Python Forum
calling a function which takes a dictionary as argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling a function which takes a dictionary as argument
#2
You don't need to use the **kwarg syntax to just pass a dict to a function.
**kwarg is used for passing a number of keyword arguments. Any keyword arguments the signature doesn't explicitly handle are put in the kwarg dict doing this.

anyway... this is all you need:
dic = {3:0.2, 4:0.5, 5:0.1, 6:0.8, 7:0.34}
 
def function(dic):
   if not dic:
      return dic
   else:
      dic[100] = 0.1
      return dic
 
function(dic)
print(dic[100])
Reply


Messages In This Thread
RE: calling a function which takes a dictionary as argument - by Mekire - Jan-03-2017, 06:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: Diagram.render() takes 1 positional argument but 2 were given sachin1361 0 328 Apr-23-2024, 06:39 AM
Last Post: sachin1361
  mutable argument in function definition akbarza 1 569 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  calling external function with arguments Wimpy_Wellington 7 1,615 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  Calling a function (which accesses a library) from another file mouse9095 4 910 Jun-07-2023, 08:55 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,216 Dec-25-2022, 03:00 PM
Last Post: askfriends
  passing dictionary to the function mark588 2 1,071 Dec-19-2022, 07:28 PM
Last Post: deanhystad
  i want to use type= as a function/method keyword argument Skaperen 9 2,077 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Error: _vhstack_dispatcher() takes 1 positional argument but 9 were given alexfrol86 3 6,047 May-09-2022, 12:49 PM
Last Post: deanhystad
Sad Iterate randint() multiple times when calling a function Jake123 2 2,167 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Calling a class from a function jc4d 5 1,965 Dec-17-2021, 09:04 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020