---
title: "python challenge 10"
author: "he_lux"
date: "2009-12-30T16:31:39Z"
tags: ["Python"]
categories: ["编程语言"]
slug: "python-challenge-10"
draft: false
lastmod: "2009-12-30T16:32:13Z"
id: 559852
url: "https://hhlux.iteye.com/blog/559852"
---

第十题。页面显示len(a) = ?。 点击页面上的图片，显示a = 
import re

if __name__ == '__main__':
    
    counter = 0
    
    def fun(s):
        
        result = ''
        
        char = s
        count = 0
                    
        for x in s:
            if x == char:
                count += 1
            else:
                result += str(count) + char
                count = 1
                char = x
                
        result += str(count) + char
        
        print(len(result))
        
        global counter
        counter += 1
        
        if counter < 30:
            fun(result)
                
    fun('1')
    
    #solution 2 Start
    def describe(s):
        sets = re.findall("(1+|2+|3+)", s)
        return ''.join(str(len(x)) + x for x in sets)
    
    s = '1'
    
    for dummy in range(30):
        s = describe(s)
        
    print(len(s))
    #solution 2 End