python - converting a list of 2 digit string numbers to a list of 2 digit integers


I have a list of 2 character strings of numbers, I'm trying to write a function to convert this to a list of 2 digit integers without using int() or knowing the length of the list, this is my code so far:

intslist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
            19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
            36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
            53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
            70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
            87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]

numslist = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
            '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23',
            '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34',
            '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45',
            '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56',
            '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67',
            '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78',
            '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
            '90', '91', '92', '93', '94', '95', '96', '97', '98', '99']

def convert_num(numlist,list1,list2):
    returnlist = []
    templist = []
    convertdict = {k:v for k,v in zip(list1,list2)}
    p = 0
    num = ''.join(numlist)
    for c in num:
        templist.append(convertdict[num[p]])
        p += 2
    for i in templist:
    if templist[i] % 2 == 0:
        returnlist.append()
    return returnlist

this works but only returns a list of the individual digits, not the 2 digits i want.

I'm only a beginner and don't really know how to proceed. Any help appreciated!!


Answer

An integer is an integer. "Two digit integers" don't exist as a concept.

Without using int or len, to return an integer from a string, you can reverse a string, use ord instead of int, multiply by 10k and sum:

x = '84'

res = sum((ord(val)-48)*10**idx for idx, val in enumerate(reversed(x)))  # 84

You can use map to apply the logic to every string in a list:

def str_to_int(x):
    return sum((ord(val)-48)*10**idx for idx, val in enumerate(reversed(x)))

res = list(map(str_to_int, numslist))

print(res)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
 ...
 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]