I am trying to iterate through a list and take each part of the list, encode it and join the result up when it is all done. As an example, I have a string which produces a list with each element being 16 characters in length.
message = (u'sixteen-letters.sixteen-letters.sixteen-letters.sixteen-letters.')
result = split16(message, 16)
msg = ';'.join(encode(result.pop(0)) for i in result)
The encode function takes a 16 byte string and returns the result, however with the way it is written, it only encodes half of the elements in th list. ie, if there are 4 elements in the list, only 2 will be encoded. If there are 6, it only does 3.
If i try comprehension:
result = [encode(split16(message, 16) for message in list_of_messages)]
result = ''.join(result)
It results in the whole list being sent at once. What i need to do is send each element to the encode function separately, get the result then join them together.
Is there an easy way of achieving this ?