For loop appending wrong Value

Hey guys I'm missing something here I want to append 'a' to my answers if the two values match and 'b' if they don't but it always appends 'b'

so the number before the word should be equal to the length of the word

import re

def is_a_valid_message(message):
answers = []
x = re.findall(r"([0-9]+)([a-zA-Z]+)", message)    
for k  in x:
    y = len(k[1])
    z = k[0]
    if y == z:
        print(k[0], k[1])   
        print(k[0], len(k[1]))   

The first test string is "3hey5hello2hi"

which outputs

3 3
5 5
2 2
['b', 'b', 'b']


Read more here:

Content Attribution

This content was originally published by widgey at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: