0

hi all,

when i am running a Python script that i made, i get a list as a result
( i do not know the number of items stored in that list )

HOW can i return each element of the list
and store in an array defined in a unix script ?

thanx

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by sravan953
0

I don't know what you mean by:

store in an array defined in a unix script ?

-but, to return each element:

# since you used 'return' I assume you want a function
# l1 is a an empty list
>>> l1=[]
>>> for x in range(3):
	l1.append(raw_input("..."))

	
...1
...2
...3
# In the for loop, instead of 3, use any number of you choice
>>> n=0
>>> def retl1():
	return l1[n]

# The return statement returns the value as you wanted it
>>> for x in range(3):
	element=retl1()
	n+=1


# Since you want to return 'each element', use a for loop to iterate
# through the elements
>>>

Edited by sravan953: Tagging mistake

0

I don't know what you mean by:


-but, to return each element:

# since you used 'return' I assume you want a function
# l1 is a an empty list
>>> l1=[]
>>> for x in range(3):
	l1.append(raw_input("..."))

	
...1
...2
...3
# In the for loop, instead of 3, use any number of you choice
>>> n=0
>>> def retl1():
	return l1[n]

# The return statement returns the value as you wanted it
>>> for x in range(3):
	element=retl1()
	n+=1


# Since you want to return 'each element', use a for loop to iterate
# through the elements
>>>

Very well explained. Good job!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.