I am trying to convert a string to a char array then loop through each char in the array and compare against dictionary keys and then if they match print the key value and move to next char in array
I have gathered some examples and tried to work it out in my head. I am new to python and have come back to programming as a hobby after a long time to try and teach my 10 year old son. He was talking about binary and i said we could write a program in python that could for example take his name as input and print his name in binary code.
#binary table is formatted such i have shortened it for simplicity
binaryTable = {
"a" : "01100001",
"b" : "01100010",
"c" : "01100011",
"d" : "01100100"
}
word = input('please input a value to see its representation in Binary Code: ')
def split(letters):
return [char for char in letters]
def members(dictArg, keysListArg):
count = 0
for x in newArray:
if newArray[x] == binaryTable.keys():
value = binaryTable.keys()
print(newArray[x])
print(' : ')
print(value)
count += 1
return count
def printBinary(dictArg, keysListArg):
count = 0
for list_item in keysListArg:
if list_item in dictArg:
count+= 1
print(count)
print(list_item)
print(' : ')
#print(keysListArg)
#print(dictArg) #print dictArg.Key() How to do this
print('\n')
return count
print('testing printBinary function\n')
newArray = split(word)
#members(newArray, binaryTable)
printBinary(newArray. binaryTable)
If i were to put say abcd i would like the output to be a new dictionary with the chars in word with their binary key representatives or just to print the letter keys in the for loop iteration #next to the representative binary value eg
j : 0110101
a : 0101010
m : 0101010
e : 0101010
s : 0101010
output:
1
a
:
2
e
:
3
j
:
4
m
:
5
s
:
['j', 'a', 'm', 'e', 's']
>>>
*Why do the keys not come out in the same order?