I have a small bot for social network, which accepts message "unicode XXXX XXXX XXXX ..."
, where XXXX
- HEX values which I should convert to Unicode characters. Initially command accepted only one HEX value, and it worked fine and fast. After I modified code to accept multiple values, process slowed down (1-2 seconds response vs. 4-5 seconds).
Here is my code:
def unic(msg):
if type(msg) == list:
msg.pop(0) # removing "unicode" word
try:
sym = '' # final result
correct = [] # correct HEX values to be converted
for code in msg:
try:
chr(int(code, 16))
correct.append(code)
except:
pass
if correct != []:
for code in correct:
sym = sym + chr(int(code, 16))
elif correct == []:
return c_s.get('incorrect') # returning error message from common strings list
if sym != '':
return sym
except:
return c_s.get('incorrect')
What should I change here to accelerate process? Any suggestions are welcome.