A Python interview question: given d = [true, False, True, False, true], use list D to return the list in just one sentence [0,2,4]

Source: Internet
Author: User

Preface: Or I, a naively small white, risking his life to the company of a forced lattice interview, go to interview on the way to experience some twists and turns, the bus death not come, finally almost missed the interview time, this is not what, although the interview does not hold any hope, But the technical side was abused into slag also really hit my self-confidence, and finally the interviewer looked like a mentally retarded look (distressed himself for half a minute).

  Title: Give d = [True, False, True, False, true], use list D to return the list in just one sentence [0,2,4]

  The key to this problem is to get the index value of true, initially I used the index method of list with the higher order function filter to solve, but I ignored the index can only get the first true indexes (that is, 0). There is no answer to the question on the Internet, so I went to search how to get the same worthy index and be inspired, so I thought of the following three methods. If you have a different solution, please also reply in the message, we communicate together and progress together.

  

 

  

A Python interview question: given d = [true, False, True, False, true], use list D to return the list in just one sentence [0,2,4]

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.