Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reverse word
#5
There is built-in module textwrap which can be used to get desired results:

>>> from textwrap import wrap
>>> a = 'python'
>>> ''.join(reversed(wrap(a, width=2)))         # [::-1] can be used instead of reversed
onthpy
Just for fun: inefficient mental exercise :

>>> a = 'python'
>>> ''.join([a[a.index(x):a.index(x) + 2] for x in a][::2][::-1])
onthpy
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Reverse word - by xSphere - Jan-28-2019, 08:17 AM
RE: Reverse word - by mlieqo - Jan-28-2019, 09:15 AM
RE: Reverse word - by xSphere - Jan-28-2019, 10:06 AM
RE: Reverse word - by perfringo - Jan-28-2019, 09:40 AM
RE: Reverse word - by perfringo - Jan-28-2019, 11:43 AM
RE: Reverse word - by chesschaser - Jul-02-2020, 04:00 PM
RE: Reverse word - by pyzyx3qwerty - Jul-02-2020, 04:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,488 Aug-12-2021, 04:25 PM
Last Post: palladium
  Python Speech recognition, word by word AceScottie 6 15,985 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  Reverse the string word sneha 2 2,620 Dec-12-2019, 03:37 AM
Last Post: sneha
  print a word after specific word search evilcode1 8 4,820 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  difference between word: and word[:] in for loop zowhair 2 3,665 Mar-03-2018, 07:24 AM
Last Post: zowhair

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020