Переменная имеет имя и значение.
Словарь представляет собой набор имен, связанных со значениями. Таким образом, для ваших целей вы могли бы сделать словарь и рассматривать его как «набор переменных».
Например, если вы хотите, «одиночные переменные» для каждой буквы х, чтобы быть счетчики, то вы можете использовать этот код:
def stats():
x = raw_input("Letters i want to extract: ")
data = raw_input("Text I want to do some stats on: ")
# make a dictionary of letters in x
d = {}
for chr in x:
d[chr] = 0 # initialize counter
# collect stats
for item in data:
if item in d:
d[item] += 1
# show results in a couple of ways
print "The full tally: %r" % d
for chr in x:
print "There were %d occurrences of %c in the text" % (d[chr], chr)
Вот пример запуска.
>>> stats()
Letters i want to extract: bell
Text I want to do some stats on: hello world
The full tally: {'b': 0, 'e': 1, 'l': 3}
There were 0 occurrences of b in the text
There were 1 occurrences of e in the text
There were 3 occurrences of l in the text
There were 3 occurrences of l in the text
'для single_letter в x'? – squiguy