def test_distinct(data):
if len(data) == len(set(data)):
return True
else:
return False;
print(test_distinct([1,5,7,9]))
print(test_distinct([2,4,5,5,7,9]))
True
False
def remove_nums(int_list):
#列表下标从 0 开始
position = 3 - 1
idx = 0
len_list = (len(int_list))
while len_list>0:
idx = (position+idx)%len_list
print(int_list.pop(idx))
len_list -= 1
nums = [10,20,30,40,50,60,70,80,90]
remove_nums(nums)
30
60
90
40
80
50
20
70
10
string_words = '''Python is a programming language that lets you work quickly
and integrate systems more effectively.'''
word_list = string_words.split()
word_freq = [word_list.count(n) for n in word_list]
print("字符串:\n {} \n".format(string_words))
print("列表:\n {} \n".format(str(word_list)))
print("各单词出现的频率是:\n {}".format(str(list(zip(word_list, word_freq)))))
字符串:
Python is a programming language that lets you work quickly
and integrate systems more effectively.
列表:
['Python', 'is', 'a', 'programming', 'language', 'that', 'lets', 'you', 'work', 'quickly', 'and', 'integrate', 'systems', 'more', 'effectively.']
各单词出现的频率是:
[('Python', 1), ('is', 1), ('a', 1), ('programming', 1), ('language', 1), ('that', 1), ('lets', 1), ('you', 1), ('work', 1), ('quickly', 1), ('and', 1), ('integrate', 1), ('systems', 1), ('more', 1),
('effectively.', 1)]
import platform as pl
os_profile = [
'architecture',
'machine',
'node',
'platform',
'processor',
'python_version',
'system',
'version',
]
for key in os_profile:
if hasattr(pl, key):
print(key + " : " + str(getattr(pl, key)()))
architecture : ('64bit', 'WindowsPE')
machine : AMD64
node : Donsole
platform : Windows-7-6.1.7601-SP1
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
python_version : 3.8.3
system : Windows
version : 6.1.7601
def permute(nums):
result_perms = [[]]
for n in nums:
new_perms = []
for perm in result_perms:
for i in range(len(perm)+1):
new_perms.append(perm[:i] + [n] + perm[i:])
result_perms = new_perms
return result_perms
my_nums = [1,2,3]
print("给定列表数字的排列可能有:\n",permute(my_nums))
给定列表数字的排列可能有:
[[3, 2, 1], [2, 3, 1], [2, 1, 3], [3, 1, 2], [1, 3, 2], [1, 2, 3]]
今天又和大家一起学习了 10 道 Python 练习题;大家都学会了吗?
联系客服