Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Shape of an array

Python 2, 37 bytes l=input() while 1:print len(l);l=l[0] Try it online! This makes heavy use of programs being allowed to terminate with error, which I assume is allowed by default because ...

posted 3y ago by xnor‭

Answer
#1: Initial revision by user avatar xnor‭ · 2020-11-23T07:59:17Z (over 3 years ago)
# [Python 2], 37 bytes

<!-- language-all: lang-python -->

    l=input()
    while 1:print len(l);l=l[0]

[Try it online!][TIO-khu9c4rz]

[Python 2]: https://docs.python.org/2/
[TIO-khu9c4rz]: https://tio.run/##NYyxCsMgEIZ3n@JwUnBI29BCSsYO3bsdTulBhMOIWKpPb42hy9338d9/oaR18@f6XR0TnCYBKZaJMi1Sysqz8@GTlBb/PETnEzB5xfrOM@Nga7sUQHmhkEA9/ZvyI8YtGniVQB11@wu9WtGK1hGItg9z7NGMDQdz6Ya7XO3BeNuTJvYH "Python 2 – Try It Online"

This makes heavy use of programs being allowed to terminate with error, which I assume is allowed by default because it is on SE. We repeatedly print the length, and then replace the list with its first entry. This will fail when we're at a leaf, which is when the list is empty or is actually a number.