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

Member Avatar for sravan953

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
>>>

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!

Member Avatar for sravan953

Very well explained. Good job!

Thanks gmilby

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.