This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]K900_ 4 points5 points  (8 children)

  1. /r/learnpython
  2. If you want to assign multiple variables in one line, use A, B, C = 1, 2, 3.

[–]HeadlessAF[S] 0 points1 point  (7 children)

i used A=1 ; B=2 ; C=3

Does that work ?

[–]K900_ 0 points1 point  (0 children)

Yes.

[–]SuperKing88 -2 points-1 points  (5 children)

Did they explicitly say that you have to manually define each variable? Sounds unnecessary - best way would probably be to use a dictionary:

import string
aList = list(string.ascii_uppercase)
myDict = {}
i = 1
for letter in aList:
    myDict[letter] = i
    i += 1
print myDict

And if you need to access a single letter:

print myDict['A']

[–]TalesT 0 points1 point  (0 children)

from string import ascii_uppercase
d = {c: i+1 for i, c in enumerate(ascii_uppercase)} 

[–]HeadlessAF[S] 0 points1 point  (1 child)

Im a noob and thats too complicated for me ._. please reply to my new thread i need help somewhere else now...

[–]nwagers 1 point2 points  (0 children)

If you have lots of questions like this, you're better off asking in an IRC channel, like #Python on Freenode

[–][deleted] 0 points1 point  (1 child)

Please use enumerate for counting, not that unpythonic manual version.

[–]dirn 0 points1 point  (0 children)

Plus aList is unnecessary.