-2

I have a list, List = [ 'A', 'B', 'C']

I want to return this List and print the items without ' '

def  returnTheList():
     List = [ ]
     #dosomething here
     .....
     return List

print returnTheList

My output is

['A','B','C']

I would like something like this as the output in my main.py

A
B
C

EDIT: I do not want to print in the function itself, rather in my main function. This list will be returned by the function and the caller gets a non-braces items.

Kelly
  • 213
  • 1
  • 6
  • 21

3 Answers3

2
print '\n'.join(returnTheList())

You can print line-by-line using this. Please note that this is applicable only to strings; if you have mixed e.g. integers and strings use

print '\n'.join(map(str, returnTheList()))
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
sundar nataraj
  • 8,524
  • 2
  • 34
  • 46
2
for item in returnTheList():
    print item
Hoopdady
  • 2,296
  • 3
  • 25
  • 40
1

That is a simple iteration through the list. (Also, avoid using List/list as variable names since they are python-reserved keywords):

lst = [...]

for i in lst:
    print(i)
sshashank124
  • 31,495
  • 9
  • 67
  • 76