Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
functions in a dictionary
#7
(Apr-26-2019, 06:00 AM)JohnKentzelGriffin Wrote: Is this more like what you want?

function_dictionary = {'fun1':lambda a:a*a, 'fun2': lambda a:a+a}
print function_dictionary['fun1'](3) # prints 9
print function_dictionary['fun2'](7) # prints 14

what if i have 85 functions to put in there, except on Tuesday only 84?

(Apr-26-2019, 06:34 AM)DeaD_EyE Wrote: Python is very flexible.

indeed, it is. but some people discourage doing some things certain ways.

do you like this way of making a dictionary?
    fun_stuff = dict(
        identity = lambda x:x,
        square   = lambda x:x*x,
        cube     = lambda x:x*x*x,
    )
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 2,825 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