Login Register


Morse Encode/Decode Class filter_list
Author
Message
RE: Morse Encode/Decode Class #11
(04-23-2013, 12:31 PM)Ex094 Wrote: Understood! Sorry Deque for putting such a mess! I didn't had the time to properly correct as I was a little busy of my own, I've done the work now and I think it meets your needs now!

It's perfect now.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Morse Encode/Decode Class #12
This:
Code:
store = store + morse_encode[item] + ' '
And this:
Code:
store = store + ' ' + morse_decode[item]

Could be shortened with += though.

Code:
store += morse_encode[item] + ' '

Code:
store += ' ' + morse_decode[item]
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Morse Encode/Decode Class #13
(04-24-2013, 01:27 AM)ArkPhaze Wrote: This:
Code:
store = store + morse_encode[item] + ' '
And this:
Code:
store = store + ' ' + morse_decode[item]

Could be shortened with += though.

Code:
store += morse_encode[item] + ' '

Code:
store += ' ' + morse_decode[item]

Good Suggestion, Thanks alot! Fixed that in the main code Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Morse Encode/Decode Class #14
I'm still a novice to intermediate in Python, but I'm also wondering if you could make that morse_decode variable a constant in that class? Or at least a static value? It never changes, but is used as reference, so declaring it in both functions within the class is about the last thing I could see about this code that could be improved. Perhaps a global? I'll take a look in a bit, I have to go in about 3 minutes, so i'm rushing my thought process here...
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Morse Encode/Decode Class #15
(04-25-2013, 12:28 AM)ArkPhaze Wrote: I'm still a novice to intermediate in Python, but I'm also wondering if you could make that morse_decode variable a constant in that class? Or at least a static value? It never changes, but is used as reference, so declaring it in both functions within the class is about the last thing I could see about this code that could be improved. Perhaps a global? I'll take a look in a bit, I have to go in about 3 minutes, so i'm rushing my thought process here...
I'm not that experienced either Biggrin So you are saying that to declare a variable in the encode function which will take the encoded value and decode it at the same moment hence presenting both results, is this what you are saying?
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Morse Encode/Decode Class #16
(04-25-2013, 05:32 AM)Ex094 Wrote:
(04-25-2013, 12:28 AM)ArkPhaze Wrote: I'm still a novice to intermediate in Python, but I'm also wondering if you could make that morse_decode variable a constant in that class? Or at least a static value? It never changes, but is used as reference, so declaring it in both functions within the class is about the last thing I could see about this code that could be improved. Perhaps a global? I'll take a look in a bit, I have to go in about 3 minutes, so i'm rushing my thought process here...
I'm not that experienced either Biggrin So you are saying that to declare a variable in the encode function which will take the encoded value and decode it at the same moment hence presenting both results, is this what you are saying?

What? no.. What i'm saying is that you're re-declaring the variable regardless of the function being called though.

edit: I didn't notice before that things were reversed in your variables.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Morse Encode/Decode Class #17
Here is what I meant:
Code:
class ex094morse: morse_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' morse_encode = ['.-', '-...', '-.-.', '-.', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.','...' ,'-' ,'..-' ,'...-' ,'.--' ,'-..-' ,'-.--' ,'--..' ,'-----' ,'.----','..---','...--','....-','.....','-....','--...','---..','----.'] def encode(self, text): store = '' for item in text.upper(): store += self.morse_encode[self.morse_alpha.find(item)] + ' ' return store def decode(self, text): store = '' for item in text.split(): store += ' ' + self.morse_alpha[self.morse_encode.index(item)] return store

Example usage:
Code:
x = ex094morse() print(x.encode('test')) print(x.decode('- . ... - '))

Not sure if I got the encoded values and the decoded values matched up properly, but that's the way I would do it. Then you can reference the variables without having to redeclare them in every function in the class.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Morse Encode/Decode Class #18
(04-25-2013, 09:46 AM)ArkPhaze Wrote: Here is what I meant:
Code:
class ex094morse: morse_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' morse_encode = ['.-', '-...', '-.-.', '-.', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.','...' ,'-' ,'..-' ,'...-' ,'.--' ,'-..-' ,'-.--' ,'--..' ,'-----' ,'.----','..---','...--','....-','.....','-....','--...','---..','----.'] def encode(self, text): store = '' for item in text.upper(): store += self.morse_encode[self.morse_alpha.find(item)] + ' ' return store def decode(self, text): store = '' for item in text.split(): store += ' ' + self.morse_alpha[self.morse_encode.index(item)] return store

Example usage:
Code:
x = ex094morse() print(x.encode('test')) print(x.decode('- . ... - '))

Not sure if I got the encoded values and the decoded values matched up properly, but that's the way I would do it. Then you can reference the variables without having to redeclare them in every function in the class.

Oh, Yeah that definitely was a valuable edit, Thanks! I've added your coded under my thread as a modified one by you Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply







Users browsing this thread: