Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:13:43+00:00 2026-06-04T16:13:43+00:00

ant=[‘1’] round = 30 while round: ant += ‘!’ next = [] start =

  • 0
ant=['1']  
round = 30  

while round:  
    ant += '!'  
    next = []  
    start = 0  

    for current in range(len(ant)):  
        if ant[current] != ant[start]:  
            next.append(str(current-start)+ant[start])  
            start = current  
    ant = "".join(next)  

    round-=1  

print len(ant)  

I got this source in a blog and tried to run this on 3.2.

(It’s about making the ant sequence. [1,11,12,1121,&c]

But at line 10, ‘IndexError : string index out of range’ pops and I hardly understand why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:13:44+00:00Added an answer on June 4, 2026 at 4:13 pm

    your code is run fine on my computer. My python version is 2.7

    the len(ant) is 5808

    But I think you python code is not very clear and not pythonic. You can read this link and this

    for example, use this

    for index, x in enumerate(ant):
    

    instead of for current in range(len(ant)):

    And don’t use ant +='!'. It should be ant.append('!')

    Good Luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ant in Eclipse has the global property WEBLOGIC_HOME but while it gives a correct
I've got an Ant task (using the maven task) set up to automatically download
I'm using Ant and mxmlc to compile ActionScript classes and MXML into swfs, while
I have the following ant snippet <macrodef name=webapp.start> <attribute name=name /> <sequential> <!--deploy--> <antcall
Ant seems to be pretty bad as running interactive program. So for instance, a
The Ant war task does just that - creates WEB-INF along with META-INF, depending
with ant it is possible to run JUnit tests and generate test reports in
I'm using an Ant build script to collate my Eclipse-based application for distribution. One
It seems that ant dependency management isn't great to say the least... But, is
How would you execute ant tasks at different phases in a maven build cycle?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.