Click to See Complete Forum and Search --> : Array in Python


dannybunkins
07-17-2005, 10:33 PM
Hi I have completed numerous python tutorials and havn't been able to find an array-like function.

I need an array-like function that I would be able to store an user defined amount of strings into it.

I am sure something like this exists, but since I am not yet 100% proficient with all python syntax and lingo I am not sure what to search for.

I have searched, and have been searching on and off ever since I started learning python, which has been a few months now.

if someone could just point me in the right direction or give me a keyword to search for I would be very appreciative.

I thank you in advance for any reply and apologize in advance for any irritation I may cause due to my ignorance and inability to find a probably painfully simple solution.

I really love python and hope to master it or at least come close, sometime in the near future.

thanks, daniel

nephish
07-17-2005, 11:49 PM
do you want to be able to reference those by a key ? for that you use a dictionary.

like this

MyDict = {'firstItem' : 'one', 'second_item' : 'two'}

then you can reference one item by its key

or you can just use a list and reference by index.

is this what you were after ? if not please specify a bit more on what you want to happen.

nephish
07-18-2005, 12:06 AM
nice screen shot on the other thread by the way

Hypz
07-18-2005, 12:34 AM
Also...

http://www.arson-network.com/index.php?class=tutorial&subargs=281

dannybunkins
07-18-2005, 11:03 AM
hey thanks guys, that looks like it will work perfectly.

dannybunkins
07-19-2005, 11:58 AM
is this possible:

stringList = []

count = 0
otherInt = 13

while count <= other int
stringList[count] = raw_input("enter a random string")
count = count + 1

just wondering if this is even possible. So far I dont think it is since my real one hasn't worked yet, but if anybody has any ideas, please post.

bwkaz
07-19-2005, 07:20 PM
When you're doing Python, PLEASE use the [code] tags, since whitespace is significant. Thanks!

What I'd actually do in this case is something like this:

#!/usr/bin/env python

stringList = []

otherInt = 13

for i in range(otherInt):
stringList.append(raw_input("enter a random string")) The range() function returns a sequence of integers in a range. The default lower bound is 0, and the upper bound is one less than the number you give it as an argument. So range(13) gives you a sequence containing the numbers 0 through 12 (13 numbers).

When you say it isn't working, what error do you get?

dannybunkins
07-20-2005, 12:08 PM
thanks bwkaz that worked perfectly, I really appreciate all of the help on this thread it has really taught me alot about python.

Ill be sure to use the [code] tag from now on.

thanks again

-dannybunkins