Python elements are re-scrambled together

Source: Internet
Author: User

Suppose Aaa= "James", write out all combinations of letters, such as AMESJ,MESJA ...

Import itertoolsaaa=list (Itertools.permutations ("James", 5)) #核心语句, followed by 5, that is, 5 letters are arranged for I in Aaa:print ("". Join (i)) # I is a string that uses a join to fit a single string element

"Comment" permutations is the whole arrangement, but there is also a usage called combinations, this usage is not repeated arrangement, such as Itertools.combinations ("abc", 2) words, ("A, B") and ("B.", "a") As the result is the same, and permutation the result as two results.


This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1775549

Python elements are re-scrambled together

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.