خرید بک لینک

Vote count: 0

I am writing a cypher and I've assigned numerical values to every letter in the alphabet, alphabet_dictionary = {'a': 0, 'b': 1, 'c': 2,... etc.}. I first convert the letter in message to numbers and do some arithmetic on them and store those numbers in a variable named code, but then I want to convert them back to letters, how do I go about doing that?

so far this is what I have:

for number in code:
    for letter, value in alphabet_dictionary.items():
        if value == number:
            coded_message.append(letter)

this actually works, I end up with a the correct coded message inside my coded_message list. But I am wondering if there is something better or more efficient I can do.

ps: If you could please also explain to me why I can't do that in a single line I would really appreciate it. I first tried using:

for number in code:
    coded_message.append(letter for letter, value in alphabet_dictionary.items() if value == number)

but that only appends the memory allocation address for the individual characters for example:

`[<generator object <genexpr> at 0x1011bb240>, <generator object <genexpr> at 0x1011bb1f8>, <generator object <genexpr> at 0x1011bb288>, <generator object <genexpr> at 0x1011bb2d0>, <generator object <genexpr> at 0x1011bb318>, <generator object <genexpr> at 0x1011bb360>, <generator object <genexpr> at 0x1011bb3a8>]'

so yeah... I am kinda intrigued by why this is happening. I am super new to coding so if I am making some idiotic mistake plz don't hesitate to call me on it thanks your time and thanks for the help guys. ;)

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 12 فروردين 1395 ساعت: 11:57

صفحه بندی