Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
functions in a dictionary
#1
it has been said not to define functions by assigning a lambda. but i want to have a dictionary (or list as the use case may be) contain a bunch of functions (perhaps small ones). i see no easy way to do this with def:
def function_collection['foobah'](a): # invalid syntax
    return a*a+a
the only clean way looks like:
function_collection['foobah'] = lambda a:a*a+a
is this an OK exception?

yeah, i know you can do a def then assign that name to the dictionary item. but that just looks so ugly:
def foobah(a):
     return a*a+a
function_collection['foobah'] = foobah
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
functions in a dictionary - by Skaperen - Apr-25-2019, 11:05 PM
RE: functions in a dictionary - by woooee - Apr-26-2019, 12:25 AM
RE: functions in a dictionary - by Skaperen - Apr-26-2019, 03:45 AM
RE: functions in a dictionary - by Skaperen - Apr-27-2019, 12:24 AM
RE: functions in a dictionary - by perfringo - Apr-26-2019, 06:21 AM
RE: functions in a dictionary - by DeaD_EyE - Apr-26-2019, 06:34 AM
RE: functions in a dictionary - by rxndy - Apr-27-2019, 02:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  functions and dictionary spalisetty06 3 1,936 Aug-22-2020, 04:50 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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