Python tips 01 Recursive interpretation inline

Source: Internet
Author: User

Now suppose there is a list of robotic accessories list[Head, torso, limb]

This list has a nose, eyes, mouth, these little parts.

This list of limbs has arms, shoulders, and hands. Hand, this list has 3 different fingers.

So this list is written in detail:

LIST=[[1,2,3,4],5,[6,7,[8,9,10]] #我们type (list) It's totally list.

We need to explain this list, after all, it is not in line with the aesthetic, and for programming unfamiliar people will not look ah.

Do we have to write a lot for the For loop print this ist?

For Each_item in list if Isinstance (each_item,list): For Eacha_item in Each_item:if isinstance (eacha_item,list): For Eachaa_item in Eacha_item:if isinstance (eachaa_item,list): for Eachaaa_item in Eachaa_ite M:print (Eachaaa_item) else:print (Eachaa_item) else:print (Eacha_item) E Lse:print (Each_item)

#当你打完这些你一定会mmp的, easy to hit the wrong to say, a lot of repeating code!

def print_99 (list): For Each_item in List:if isinstance (each_item,list): print_99 (Each_item) else:print (Each_item)

Things are so happy to solve, this programming idea, feeling a lot, seems to have some understanding of object-oriented programming. I think of myself for one hours, it seems that this is the way, very way

Python tips 01 Recursive interpretation inline

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.