0

I have a counter:

count = []

def count_up(digit_1, digit_2, digit_3, digit_4, digit_5, digit_6,     digit_7):
    if(tick = True):
        count = []
        digit_1 = digit_1 + 1
        if(digit_1 == 27):
            digit_1 = 0
            digit_2 += 1
            if(digit_2 == 27):
                digit_2 = 0
                digit_3 += 1
                if(digit_3 == 27):
                    digit_3 = 0
                    digit_4 += 1
                    if(digit_4 == 26):
                        digit_4 = 0
                        digit_5 += 1
                        if(digit_5 == 26):
                            digit_5 = 0

    count.append(digit_1)
    count.append(digit_2)
    count.append(digit_3)
    count.append(digit_4)
    count.append(digit_5)
    print count
    count = []

and I want to change each digit in the list to the corresponding letter (1 = a, 26 = z)

I have tried .replace() but it comes up with:

File "/Users/Johnpaulbeer/pythonpractice/test.py", line 99, in >count_decoder count = [w.replace(1, 'a') for w in count] AttributeError: 'int' object has no attribute 'replace'

What else can I do, or if not then how do I change the integer into a string?

2
  • 1
    Why are you trying to simulate a dict() with a list()? Commented Nov 30, 2016 at 19:19
  • Have you tried the map function? Commented Nov 30, 2016 at 19:19

1 Answer 1

4

I'm interpreting your question as, "given a list of numbers between 1 and 26, how do I get a list of characters between a and z?". You could do:

count = [chr(w + ord("a") - 1) for w in count]

Example:

>>> count = [8, 5, 12, 12, 15, 23, 15, 18, 12, 4]
>>> count = [chr(w + ord("a") - 1) for w in count]
>>> count
['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.