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

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 7 Years Ago by sravan953: Tagging mistake

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 article has been dead for over six months. Start a new discussion instead.