Python functions within lists

0 votes

So I inquired about utilising a function as a variable in computer science today. For example, I may write a function called returnMe(i) and an array to call it from. For example, if h = [help,returnMe], I may say h1 and it will call returnMe ("Bob"). I apologise for being a little too enthusiastic about this. Is there a way to define a function that only appears in the array using something like h.append(def function)?

EDIT:

Here's some code I created using it! So, I just finished a fantastic FizzBuzz with your answer, and I want to thank you again! As an example, consider the following code:

funct = []
s = ""

def newFunct(str, num):
    return (lambda x: str if(x%num==0) else "")

funct.append(newFunct("Fizz",3))
funct.append(newFunct("Buzz",5))

for x in range(1,101):
    for oper in funct:
        s += oper(x)
    s += ":"+str(x)+"\n"

print s
Apr 12, 2022 in Python by Edureka
• 12,690 points
319 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.

Related Questions In Python

0 votes
1 answer

Run Unix command within Python

From the python docs, use the subprocess ...READ MORE

answered Apr 27, 2018 in Python by Nietzsche's daemon
• 4,260 points
671 views
0 votes
1 answer

Copying lists in python

Assigning one list to another one simply ...READ MORE

answered Apr 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
673 views
0 votes
1 answer

Difference between two lists in python

difference = list(set(list1) - set(list2)) READ MORE

answered May 24, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,793 views
0 votes
1 answer

Using Lists and Tuples in Python

if you are familiar with C programming, ...READ MORE

answered May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
984 views
0 votes
1 answer

Python: list of lists

Lists are a mutable type - in ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 15,520 points
711 views
+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 58,100 points
2,346 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,394 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