Python functions within lists

0 votes
Is there a way of calling like h.append(def function) and define a function that only exists in the array?
Apr 14, 2022 in Azure by Edureka
• 13,620 points
401 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

17

You can create anonymous functions using the lambda keyword.

def func(x,keyword='bar'):
    return (x,keyword)

is roughly equivalent to:

func = lambda x,keyword='bar':(x,keyword)

So, if you want to create a list with functions in it:

my_list = [lambda x:x**2,lambda x:x**3]
print my_list[0](2)  #4
print my_list[1](2)  #8
answered Apr 26, 2022 by Edureka
• 12,690 points

edited Mar 5

Related Questions In Azure

0 votes
1 answer

Add run id when registering ml.azure model via python (pipeline)

Create the following resources in order to ...READ MORE

answered Mar 1, 2022 in Azure by Edureka
• 12,690 points
1,048 views
0 votes
0 answers

Azure Functions not showing up in Function app in portal

I've got a solution that contains a ...READ MORE

Mar 26, 2022 in Azure by Edureka
• 13,620 points
3,349 views
0 votes
1 answer

How to download Azure Function (Python) .zip file?

You can use ftp to get app ...READ MORE

answered Mar 29, 2022 in Azure by Edureka
• 12,690 points
2,949 views
0 votes
1 answer

Publishing events to azure event grid via azure functions

Event Grid is an Azure service that ...READ MORE

answered Apr 1, 2022 in Azure by Edureka
• 12,690 points
1,032 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,678 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP