Python Forum
Python Program For Finding Sub String Of Given String
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Program For Finding Sub String Of Given String
#1
name = input().strip()

print("\n".join(name[i: i + j] for i in range(len(name)) for j in range(1, len(name) + 1 - i)))
Reply
#2
Strange, It isn't working for me. Confused
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
works when I try it (from interactive python)
Python 3.8.1 (default, Dec 19 2019, 16:08:07) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> name = input().strip()
harry
>>> print("\n".join(name[i: i + j] for i in range(len(name)) for j in range(1, len(name) + 1 - i)))
h
ha
har
harr
harry
a
ar
arr
arry
r
rr
rry
r
ry
y
>>>
and from script:
(venv) src$ python pjscript.py
harry
h
ha
har
harr
harry
a
ar
arr
arry
r
rr
rry
r
ry
y
Reply
#4
Wait, its supposed to do that? Then it works for me. I didn't know what it was supposed to do. My bad :)
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  recursion used to convert string into sum fred1232 0 1,533 Nov-08-2021, 10:33 PM
Last Post: fred1232

Forum Jump:

User Panel Messages

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