Issue
wrap
in textwrap
wraps from left to right:
from textwrap import wrap
print(wrap('1100010101', 4))
returns: ['1100', '0101', '01']
Is there a way to wrap it from right to left, so it returns: ['11', '0001', '0101']
?
Solution
You can first reverse '1100010101'
then reverse each element and at end reverse result of wrap
like below:
>>> from textwrap import wrap
>>> st = '1100010101'[::-1]
>>> list(map(lambda x: x[::-1] , wrap(st, 4)))[::-1]
['11', '0001', '0101']
Answered By - user1740577
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.