Please note: This wiki is currently running in test mode after an attack on January 5 2013. All passwords were reset, so you will have to use the password recovery function to get a new password. To edit wiki pages, please log in first. See the wiki attack description page for more details. If you find problems, please report them to the pydotorg-www mailing list.

Your search query "linkto:"Asking for Help/How to store information in variable arrays?"" didn't return any results. Please change some terms and refer to HelpOnSearching for more information.
(!) Consider performing a full-text search with your search terms.

Clear message

How to store information in variable arrays?

How would I store information in variables that I can go back later and compare? Such as

   1 x = 1
   2 text = []
   3 while x <= 10:
   4      text.append(int(raw_input("Enter a number: ")))
   5      x = x + 1
   6 
   7 for x in range(10): 
   8     print text[x]

I just need to do this to compare a history to make sure a number hasn't already been entered earlier. But this is just a small example. I get nasty errors.

Thanks!

edit: that should work now We initialize a list first with text = []. Then we just append each element to that list.


You can use the in operator:

   1 if number in text:
   2     print "Number already entered!"

If you choose to use a set instead of a list...

   1 text = set()

...then the above test still works, but you'll use the add method on the set when adding numbers, not an append method.


CategoryAskingForHelp CategoryAskingForHelpAnswered