0

I'm creating a program that takes a string and converts each word in the string into a variable in ascending order from a-z. I like to name my variables in a certain way to make them easier for me to understand: s means statement, v means variable, l means list, w means word, le means length: so svlle would be statement variable list length

import time
svl = []
num = 0
letters = ['a' 'b' 'c' ... 'z']
print('test-05')
time.sleep(1)
s = input('statement:')
swl = s.split()
swlle = len(swl)
svlle = (letters[0:swlle])
while num < swlle:
    svl.append(letters[num]) 
    num = num + 1
num = 0
if ', '.join(svl) in globals():
    while svl[num] < swlle:
        svl[num] = swl[num]
        num = num + 1
else:
    print('failure?')

print(a)
print(b)
print(c)
time.sleep(3)` 

I have no idea how to take all the letters from my svl and assign them as variables for all the words in my original statement. Keep in mind that I'm designing this to be able to accept any string up to a size of 26 words and take each word to make them into a variable!

Whitewolf
  • 3
  • 5
  • 4
    Have you considered instead simply *not* doing this? It's a hassle to create the variables in the first place, then a hassle to access them again later. Use a list, or dictionary. See http://stackoverflow.com/q/1373164/3001761. – jonrsharpe Mar 27 '17 at 20:23
  • I'm going to close this as a dupe because there are only a handful of cases in which you're not better off using a list or dictionary, and this isn't one of those exceptions. – DSM Mar 27 '17 at 20:36
  • Yea, I can see how I decided to do things that are a bit unnecessary, I'll use the words from the list rather than store them as new variables and use those variables. – Whitewolf Mar 27 '17 at 20:48

0 Answers0