Python Forum

Full Version: Python Program For Finding Sub String Of Given String
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)))
Strange, It isn't working for me. Confused
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
Wait, its supposed to do that? Then it works for me. I didn't know what it was supposed to do. My bad :)