global name is not defined - error

A

a

What I want
---------------
I want to create a list of items from a function operating on an array
of strings


What I did
-----------------
list=["s0","s1","s2"]
l=len(list)
for i in range(l):
d_list=f.do(list)
print d_list

Error:
------
global name 'd_list' is not defined
Python c:\test.py in newClass, line 30

Please help me out
thanks
-a
 
B

Bruno Desthuilliers

a said:
What I want

def func(s):
return s.upper()

arrayOfStrings = ['bicycle', 'repair', 'man']

print "solution 1: with map()"
print map(func, arrayOfStrings)
print "solution 2: with list comprehension"
print [func(s) for s in arrayOfStrings]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top