Python_每日习题_0001_数字组合

# Topic: There are four digits: 1, 2, 3 and 4.
# How many different three digits can be formed without repeating numbers? How much is each?


# Procedure analysis: traverse all possibilities and shave out duplicates.

total = 0
for i in range(1,5):
    for j in range(1,5):
        for k in range(1,5):
            if i!=j and j!=k and k!=i:
                print(i,j,k)
                total += 1
print(total)



# Simple Method: Use permutations in itertools

import itertools

sum2 = 0
a = [1,2,3,4]
for i in itertools.permutations(a,3):
    print(i)
    sum2 += 1
print(sum2)
#    permutations method emphasizes permutations

import itertools
n=int(raw_input())
a=[str(i) for i in range(n)]
s=""
s=s.join(a)
for i in itertools.permutations(s,n):
    print ''.join(i)
#combinations method focuses on combination

import itertools
n=int(raw_input())
a=[str(i) for i in range(n)]
s=""
s=s.join(a)
for i in itertools.combinations(s,n):
    print ''.join(i)

 

转载于:https://www.cnblogs.com/LXL616/p/10658608.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值