How to convert a string to binary code using list and dictionaryThe order of keys in dictionariesHow to merge two dictionaries in a single expression?How do I check if a list is empty?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How do I sort a dictionary by value?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I list all files of a directory?How do I convert a String to an int in Java?

I have a unique character that I'm having a problem writing. He's a virus!

What is a smasher?

Fitch Proof Question

Randomness of Python's random

Why wasn't the Night King naked in S08E03?

Should I replace my bicycle tires if they have not been inflated in multiple years

Set collection doesn't always enforce uniqueness with the Date datatype? Does the following example seem correct?

Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?

What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?

String won't reverse using reverse_copy

How can I support myself financially as a 17 year old with a loan?

Why do people keep telling me that I am a bad photographer?

How should I tell my manager I'm not paying for an optional after work event I'm not going to?

BOOM! Perfect Clear for Mr. T

Would the Disguise Self spell be able to reveal hidden birthmarks/tattoos (of the person they're disguised as) to a character?

What property of a BJT transistor makes it an amplifier?

What happens if you dump antimatter into a black hole?

How I can I roll a number of non-digital dice to get a random number between 1 and 150?

Using column size much larger than necessary

Upside-Down Pyramid Addition...REVERSED!

How can I close a gap between my fence and my neighbor's that's on his side of the property line?

What was the design of the Macintosh II's MMU replacement?

What is the most remote airport from the center of the city it supposedly serves?

How do I tell my manager that his code review comment is wrong?



How to convert a string to binary code using list and dictionary


The order of keys in dictionariesHow to merge two dictionaries in a single expression?How do I check if a list is empty?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How do I sort a dictionary by value?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I list all files of a directory?How do I convert a String to an int in Java?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















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 functionn')

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?










share|improve this question






















  • what version of python? dict used to not guarantee order of keys when iterating. not sure of the behavior now. stackoverflow.com/questions/5629023/…

    – MFisherKDX
    Mar 22 at 22:40











  • 3.7 I edited the function as such but it still prints in the wrong order:

    – James Dean
    Mar 22 at 22:44











  • def printBinary(dictArg, keysListArg): count = 0 for list_item in keysListArg: if list_item in dictArg: count+= 1 print(count) print(list_item) print(' : ') x = keysListArg.get(list_item) print(x) return count

    – James Dean
    Mar 22 at 22:45











  • I'm having a hard time understanding what you are after ... but did you mean to call the function printBinary as printBinary(binaryTable, newArray) instead of printBinary(newArray, binaryTable) ?

    – MFisherKDX
    Mar 22 at 22:52











  • I have solved it:

    – James Dean
    Mar 22 at 22:56

















0















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 functionn')

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?










share|improve this question






















  • what version of python? dict used to not guarantee order of keys when iterating. not sure of the behavior now. stackoverflow.com/questions/5629023/…

    – MFisherKDX
    Mar 22 at 22:40











  • 3.7 I edited the function as such but it still prints in the wrong order:

    – James Dean
    Mar 22 at 22:44











  • def printBinary(dictArg, keysListArg): count = 0 for list_item in keysListArg: if list_item in dictArg: count+= 1 print(count) print(list_item) print(' : ') x = keysListArg.get(list_item) print(x) return count

    – James Dean
    Mar 22 at 22:45











  • I'm having a hard time understanding what you are after ... but did you mean to call the function printBinary as printBinary(binaryTable, newArray) instead of printBinary(newArray, binaryTable) ?

    – MFisherKDX
    Mar 22 at 22:52











  • I have solved it:

    – James Dean
    Mar 22 at 22:56













0












0








0








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 functionn')

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?










share|improve this question














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 functionn')

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?







python string binary converters






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 22:36









James DeanJames Dean

11




11












  • what version of python? dict used to not guarantee order of keys when iterating. not sure of the behavior now. stackoverflow.com/questions/5629023/…

    – MFisherKDX
    Mar 22 at 22:40











  • 3.7 I edited the function as such but it still prints in the wrong order:

    – James Dean
    Mar 22 at 22:44











  • def printBinary(dictArg, keysListArg): count = 0 for list_item in keysListArg: if list_item in dictArg: count+= 1 print(count) print(list_item) print(' : ') x = keysListArg.get(list_item) print(x) return count

    – James Dean
    Mar 22 at 22:45











  • I'm having a hard time understanding what you are after ... but did you mean to call the function printBinary as printBinary(binaryTable, newArray) instead of printBinary(newArray, binaryTable) ?

    – MFisherKDX
    Mar 22 at 22:52











  • I have solved it:

    – James Dean
    Mar 22 at 22:56

















  • what version of python? dict used to not guarantee order of keys when iterating. not sure of the behavior now. stackoverflow.com/questions/5629023/…

    – MFisherKDX
    Mar 22 at 22:40











  • 3.7 I edited the function as such but it still prints in the wrong order:

    – James Dean
    Mar 22 at 22:44











  • def printBinary(dictArg, keysListArg): count = 0 for list_item in keysListArg: if list_item in dictArg: count+= 1 print(count) print(list_item) print(' : ') x = keysListArg.get(list_item) print(x) return count

    – James Dean
    Mar 22 at 22:45











  • I'm having a hard time understanding what you are after ... but did you mean to call the function printBinary as printBinary(binaryTable, newArray) instead of printBinary(newArray, binaryTable) ?

    – MFisherKDX
    Mar 22 at 22:52











  • I have solved it:

    – James Dean
    Mar 22 at 22:56
















what version of python? dict used to not guarantee order of keys when iterating. not sure of the behavior now. stackoverflow.com/questions/5629023/…

– MFisherKDX
Mar 22 at 22:40





what version of python? dict used to not guarantee order of keys when iterating. not sure of the behavior now. stackoverflow.com/questions/5629023/…

– MFisherKDX
Mar 22 at 22:40













3.7 I edited the function as such but it still prints in the wrong order:

– James Dean
Mar 22 at 22:44





3.7 I edited the function as such but it still prints in the wrong order:

– James Dean
Mar 22 at 22:44













def printBinary(dictArg, keysListArg): count = 0 for list_item in keysListArg: if list_item in dictArg: count+= 1 print(count) print(list_item) print(' : ') x = keysListArg.get(list_item) print(x) return count

– James Dean
Mar 22 at 22:45





def printBinary(dictArg, keysListArg): count = 0 for list_item in keysListArg: if list_item in dictArg: count+= 1 print(count) print(list_item) print(' : ') x = keysListArg.get(list_item) print(x) return count

– James Dean
Mar 22 at 22:45













I'm having a hard time understanding what you are after ... but did you mean to call the function printBinary as printBinary(binaryTable, newArray) instead of printBinary(newArray, binaryTable) ?

– MFisherKDX
Mar 22 at 22:52





I'm having a hard time understanding what you are after ... but did you mean to call the function printBinary as printBinary(binaryTable, newArray) instead of printBinary(newArray, binaryTable) ?

– MFisherKDX
Mar 22 at 22:52













I have solved it:

– James Dean
Mar 22 at 22:56





I have solved it:

– James Dean
Mar 22 at 22:56












1 Answer
1






active

oldest

votes


















0














#program to take a string and show the binary representation of all the letters
binaryTable =
"a" : "01100001",
"b" : "01100010",
"c" : "01100011",
"d" : "01100100",
"e" : "01100101",
"f" : "01100110",
"g" : "01100111",
"h" : "01101000",
"i" : "01101001",
"j" : "01101010",
"k" : "01101011",
"l" : "01101100",
"m" : "01101101",
"n" : "01101110",
"o" : "01101111",
"p" : "01110000",
"q" : "01110001",
"r" : "01110010",
"s" : "01110011",
"t" : "01110100",
"u" : "01110101",
"v" : "01110110",
"w" : "01110111",
"x" : "01111000",
"y" : "01111001",
"z" : "01111010",
"A" : "01000001",
"B" : "01000010",
"C" : "01000011",
"D" : "01000100",
"E" : "01000101",
"F" : "01000110",
"G" : "01000111",
"H" : "01001000",
"I" : "01001001",
"J" : "01001010",
"K" : "01001011",
"L" : "01001100",
"M" : "01001101",
"N" : "01001110",
"O" : "01001111",
"P" : "01010000",
"Q" : "01001111",
"R" : "01010010",
"S" : "01010011",
"T" : "01010100",
"U" : "01010101",
"V" : "01010110",
"W" : "01010111",
"X" : "01011000",
"Y" : "01011001",
"Z" : "01011010"


print('Hello there! I am a binary translator. Add some text to see it in binary!')
print('Below is a binary table for all characters of the Alphabet. Remember, upper and lower case characters have different binary values!')
print(
'''
Letter Binary Letter Binary
a 01100001 A 01000001
b 01100010 B 01000010
c 01100011 C 01000011
d 01100100 D 01000100
e 01100101 E 01000101
f 01100110 F 01000110
g 01100111 G 01000111
h 01101000 H 01001000
i 01101001 I 01001001
j 01101010 J 01001010
k 01101011 K 01001011
l 01101100 L 01001100
m 01101101 M 01001101
n 01101110 N 01001110
o 01101111 O 01001111
p 01110000 P 01010000
q 01110001 Q 01010001
r 01110010 R 01010010
s 01110011 S 01010011
t 01110100 T 01010100
u 01110101 U 01010101
v 01110110 V 01010110
w 01110111 W 01010111
x 01111000 X 01011000
y 01111001 Y 01011001
z 01111010 Z 01011010''')


word = input('please input a value to see its representation in Binary Code: ')

#splits the word into single letters and stores in a list aka newArray
def split(letters):
return [char for char in letters]

#takes the parameters of newArray and binaryTable.
#new array is the input word split into letters
def printBinary(dictArg, keysListArg):
for list_item in dictArg:
if list_item in keysListArg:
#grabs the binary value linked to its key and stores in x
x = keysListArg.get(list_item)
#prints list item along side its binary key
print(list_item + ' : ' + x)

#splits the word
newArray = split(word)
#prints each letter next to its binary code representation
printBinary(newArray, binaryTable)


sample output:



please input a value to see its representation in Binary Code: louis
l : 01101100
o : 01101111
u : 01110101
i : 01101001
s : 01110011
>>>





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308655%2fhow-to-convert-a-string-to-binary-code-using-list-and-dictionary%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    #program to take a string and show the binary representation of all the letters
    binaryTable =
    "a" : "01100001",
    "b" : "01100010",
    "c" : "01100011",
    "d" : "01100100",
    "e" : "01100101",
    "f" : "01100110",
    "g" : "01100111",
    "h" : "01101000",
    "i" : "01101001",
    "j" : "01101010",
    "k" : "01101011",
    "l" : "01101100",
    "m" : "01101101",
    "n" : "01101110",
    "o" : "01101111",
    "p" : "01110000",
    "q" : "01110001",
    "r" : "01110010",
    "s" : "01110011",
    "t" : "01110100",
    "u" : "01110101",
    "v" : "01110110",
    "w" : "01110111",
    "x" : "01111000",
    "y" : "01111001",
    "z" : "01111010",
    "A" : "01000001",
    "B" : "01000010",
    "C" : "01000011",
    "D" : "01000100",
    "E" : "01000101",
    "F" : "01000110",
    "G" : "01000111",
    "H" : "01001000",
    "I" : "01001001",
    "J" : "01001010",
    "K" : "01001011",
    "L" : "01001100",
    "M" : "01001101",
    "N" : "01001110",
    "O" : "01001111",
    "P" : "01010000",
    "Q" : "01001111",
    "R" : "01010010",
    "S" : "01010011",
    "T" : "01010100",
    "U" : "01010101",
    "V" : "01010110",
    "W" : "01010111",
    "X" : "01011000",
    "Y" : "01011001",
    "Z" : "01011010"


    print('Hello there! I am a binary translator. Add some text to see it in binary!')
    print('Below is a binary table for all characters of the Alphabet. Remember, upper and lower case characters have different binary values!')
    print(
    '''
    Letter Binary Letter Binary
    a 01100001 A 01000001
    b 01100010 B 01000010
    c 01100011 C 01000011
    d 01100100 D 01000100
    e 01100101 E 01000101
    f 01100110 F 01000110
    g 01100111 G 01000111
    h 01101000 H 01001000
    i 01101001 I 01001001
    j 01101010 J 01001010
    k 01101011 K 01001011
    l 01101100 L 01001100
    m 01101101 M 01001101
    n 01101110 N 01001110
    o 01101111 O 01001111
    p 01110000 P 01010000
    q 01110001 Q 01010001
    r 01110010 R 01010010
    s 01110011 S 01010011
    t 01110100 T 01010100
    u 01110101 U 01010101
    v 01110110 V 01010110
    w 01110111 W 01010111
    x 01111000 X 01011000
    y 01111001 Y 01011001
    z 01111010 Z 01011010''')


    word = input('please input a value to see its representation in Binary Code: ')

    #splits the word into single letters and stores in a list aka newArray
    def split(letters):
    return [char for char in letters]

    #takes the parameters of newArray and binaryTable.
    #new array is the input word split into letters
    def printBinary(dictArg, keysListArg):
    for list_item in dictArg:
    if list_item in keysListArg:
    #grabs the binary value linked to its key and stores in x
    x = keysListArg.get(list_item)
    #prints list item along side its binary key
    print(list_item + ' : ' + x)

    #splits the word
    newArray = split(word)
    #prints each letter next to its binary code representation
    printBinary(newArray, binaryTable)


    sample output:



    please input a value to see its representation in Binary Code: louis
    l : 01101100
    o : 01101111
    u : 01110101
    i : 01101001
    s : 01110011
    >>>





    share|improve this answer



























      0














      #program to take a string and show the binary representation of all the letters
      binaryTable =
      "a" : "01100001",
      "b" : "01100010",
      "c" : "01100011",
      "d" : "01100100",
      "e" : "01100101",
      "f" : "01100110",
      "g" : "01100111",
      "h" : "01101000",
      "i" : "01101001",
      "j" : "01101010",
      "k" : "01101011",
      "l" : "01101100",
      "m" : "01101101",
      "n" : "01101110",
      "o" : "01101111",
      "p" : "01110000",
      "q" : "01110001",
      "r" : "01110010",
      "s" : "01110011",
      "t" : "01110100",
      "u" : "01110101",
      "v" : "01110110",
      "w" : "01110111",
      "x" : "01111000",
      "y" : "01111001",
      "z" : "01111010",
      "A" : "01000001",
      "B" : "01000010",
      "C" : "01000011",
      "D" : "01000100",
      "E" : "01000101",
      "F" : "01000110",
      "G" : "01000111",
      "H" : "01001000",
      "I" : "01001001",
      "J" : "01001010",
      "K" : "01001011",
      "L" : "01001100",
      "M" : "01001101",
      "N" : "01001110",
      "O" : "01001111",
      "P" : "01010000",
      "Q" : "01001111",
      "R" : "01010010",
      "S" : "01010011",
      "T" : "01010100",
      "U" : "01010101",
      "V" : "01010110",
      "W" : "01010111",
      "X" : "01011000",
      "Y" : "01011001",
      "Z" : "01011010"


      print('Hello there! I am a binary translator. Add some text to see it in binary!')
      print('Below is a binary table for all characters of the Alphabet. Remember, upper and lower case characters have different binary values!')
      print(
      '''
      Letter Binary Letter Binary
      a 01100001 A 01000001
      b 01100010 B 01000010
      c 01100011 C 01000011
      d 01100100 D 01000100
      e 01100101 E 01000101
      f 01100110 F 01000110
      g 01100111 G 01000111
      h 01101000 H 01001000
      i 01101001 I 01001001
      j 01101010 J 01001010
      k 01101011 K 01001011
      l 01101100 L 01001100
      m 01101101 M 01001101
      n 01101110 N 01001110
      o 01101111 O 01001111
      p 01110000 P 01010000
      q 01110001 Q 01010001
      r 01110010 R 01010010
      s 01110011 S 01010011
      t 01110100 T 01010100
      u 01110101 U 01010101
      v 01110110 V 01010110
      w 01110111 W 01010111
      x 01111000 X 01011000
      y 01111001 Y 01011001
      z 01111010 Z 01011010''')


      word = input('please input a value to see its representation in Binary Code: ')

      #splits the word into single letters and stores in a list aka newArray
      def split(letters):
      return [char for char in letters]

      #takes the parameters of newArray and binaryTable.
      #new array is the input word split into letters
      def printBinary(dictArg, keysListArg):
      for list_item in dictArg:
      if list_item in keysListArg:
      #grabs the binary value linked to its key and stores in x
      x = keysListArg.get(list_item)
      #prints list item along side its binary key
      print(list_item + ' : ' + x)

      #splits the word
      newArray = split(word)
      #prints each letter next to its binary code representation
      printBinary(newArray, binaryTable)


      sample output:



      please input a value to see its representation in Binary Code: louis
      l : 01101100
      o : 01101111
      u : 01110101
      i : 01101001
      s : 01110011
      >>>





      share|improve this answer

























        0












        0








        0







        #program to take a string and show the binary representation of all the letters
        binaryTable =
        "a" : "01100001",
        "b" : "01100010",
        "c" : "01100011",
        "d" : "01100100",
        "e" : "01100101",
        "f" : "01100110",
        "g" : "01100111",
        "h" : "01101000",
        "i" : "01101001",
        "j" : "01101010",
        "k" : "01101011",
        "l" : "01101100",
        "m" : "01101101",
        "n" : "01101110",
        "o" : "01101111",
        "p" : "01110000",
        "q" : "01110001",
        "r" : "01110010",
        "s" : "01110011",
        "t" : "01110100",
        "u" : "01110101",
        "v" : "01110110",
        "w" : "01110111",
        "x" : "01111000",
        "y" : "01111001",
        "z" : "01111010",
        "A" : "01000001",
        "B" : "01000010",
        "C" : "01000011",
        "D" : "01000100",
        "E" : "01000101",
        "F" : "01000110",
        "G" : "01000111",
        "H" : "01001000",
        "I" : "01001001",
        "J" : "01001010",
        "K" : "01001011",
        "L" : "01001100",
        "M" : "01001101",
        "N" : "01001110",
        "O" : "01001111",
        "P" : "01010000",
        "Q" : "01001111",
        "R" : "01010010",
        "S" : "01010011",
        "T" : "01010100",
        "U" : "01010101",
        "V" : "01010110",
        "W" : "01010111",
        "X" : "01011000",
        "Y" : "01011001",
        "Z" : "01011010"


        print('Hello there! I am a binary translator. Add some text to see it in binary!')
        print('Below is a binary table for all characters of the Alphabet. Remember, upper and lower case characters have different binary values!')
        print(
        '''
        Letter Binary Letter Binary
        a 01100001 A 01000001
        b 01100010 B 01000010
        c 01100011 C 01000011
        d 01100100 D 01000100
        e 01100101 E 01000101
        f 01100110 F 01000110
        g 01100111 G 01000111
        h 01101000 H 01001000
        i 01101001 I 01001001
        j 01101010 J 01001010
        k 01101011 K 01001011
        l 01101100 L 01001100
        m 01101101 M 01001101
        n 01101110 N 01001110
        o 01101111 O 01001111
        p 01110000 P 01010000
        q 01110001 Q 01010001
        r 01110010 R 01010010
        s 01110011 S 01010011
        t 01110100 T 01010100
        u 01110101 U 01010101
        v 01110110 V 01010110
        w 01110111 W 01010111
        x 01111000 X 01011000
        y 01111001 Y 01011001
        z 01111010 Z 01011010''')


        word = input('please input a value to see its representation in Binary Code: ')

        #splits the word into single letters and stores in a list aka newArray
        def split(letters):
        return [char for char in letters]

        #takes the parameters of newArray and binaryTable.
        #new array is the input word split into letters
        def printBinary(dictArg, keysListArg):
        for list_item in dictArg:
        if list_item in keysListArg:
        #grabs the binary value linked to its key and stores in x
        x = keysListArg.get(list_item)
        #prints list item along side its binary key
        print(list_item + ' : ' + x)

        #splits the word
        newArray = split(word)
        #prints each letter next to its binary code representation
        printBinary(newArray, binaryTable)


        sample output:



        please input a value to see its representation in Binary Code: louis
        l : 01101100
        o : 01101111
        u : 01110101
        i : 01101001
        s : 01110011
        >>>





        share|improve this answer













        #program to take a string and show the binary representation of all the letters
        binaryTable =
        "a" : "01100001",
        "b" : "01100010",
        "c" : "01100011",
        "d" : "01100100",
        "e" : "01100101",
        "f" : "01100110",
        "g" : "01100111",
        "h" : "01101000",
        "i" : "01101001",
        "j" : "01101010",
        "k" : "01101011",
        "l" : "01101100",
        "m" : "01101101",
        "n" : "01101110",
        "o" : "01101111",
        "p" : "01110000",
        "q" : "01110001",
        "r" : "01110010",
        "s" : "01110011",
        "t" : "01110100",
        "u" : "01110101",
        "v" : "01110110",
        "w" : "01110111",
        "x" : "01111000",
        "y" : "01111001",
        "z" : "01111010",
        "A" : "01000001",
        "B" : "01000010",
        "C" : "01000011",
        "D" : "01000100",
        "E" : "01000101",
        "F" : "01000110",
        "G" : "01000111",
        "H" : "01001000",
        "I" : "01001001",
        "J" : "01001010",
        "K" : "01001011",
        "L" : "01001100",
        "M" : "01001101",
        "N" : "01001110",
        "O" : "01001111",
        "P" : "01010000",
        "Q" : "01001111",
        "R" : "01010010",
        "S" : "01010011",
        "T" : "01010100",
        "U" : "01010101",
        "V" : "01010110",
        "W" : "01010111",
        "X" : "01011000",
        "Y" : "01011001",
        "Z" : "01011010"


        print('Hello there! I am a binary translator. Add some text to see it in binary!')
        print('Below is a binary table for all characters of the Alphabet. Remember, upper and lower case characters have different binary values!')
        print(
        '''
        Letter Binary Letter Binary
        a 01100001 A 01000001
        b 01100010 B 01000010
        c 01100011 C 01000011
        d 01100100 D 01000100
        e 01100101 E 01000101
        f 01100110 F 01000110
        g 01100111 G 01000111
        h 01101000 H 01001000
        i 01101001 I 01001001
        j 01101010 J 01001010
        k 01101011 K 01001011
        l 01101100 L 01001100
        m 01101101 M 01001101
        n 01101110 N 01001110
        o 01101111 O 01001111
        p 01110000 P 01010000
        q 01110001 Q 01010001
        r 01110010 R 01010010
        s 01110011 S 01010011
        t 01110100 T 01010100
        u 01110101 U 01010101
        v 01110110 V 01010110
        w 01110111 W 01010111
        x 01111000 X 01011000
        y 01111001 Y 01011001
        z 01111010 Z 01011010''')


        word = input('please input a value to see its representation in Binary Code: ')

        #splits the word into single letters and stores in a list aka newArray
        def split(letters):
        return [char for char in letters]

        #takes the parameters of newArray and binaryTable.
        #new array is the input word split into letters
        def printBinary(dictArg, keysListArg):
        for list_item in dictArg:
        if list_item in keysListArg:
        #grabs the binary value linked to its key and stores in x
        x = keysListArg.get(list_item)
        #prints list item along side its binary key
        print(list_item + ' : ' + x)

        #splits the word
        newArray = split(word)
        #prints each letter next to its binary code representation
        printBinary(newArray, binaryTable)


        sample output:



        please input a value to see its representation in Binary Code: louis
        l : 01101100
        o : 01101111
        u : 01110101
        i : 01101001
        s : 01110011
        >>>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 23:54









        James DeanJames Dean

        11




        11





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308655%2fhow-to-convert-a-string-to-binary-code-using-list-and-dictionary%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현