'''
如果 a+b+c=1000,且 a^2+b^2=c^2(a,b,c 为自然数),如何求出所有a、b、c可能的组合?
'''for a inrange(1000):for b inrange(1000):
c =1000- a - b
if c >= a and c >= b and a **2+ b **2== c **2:print("结果:", a, b, c)'''
结果: 0 500 500
结果: 200 375 425
结果: 375 200 425
结果: 500 0 500
'''
'''
给定两个字符串,str1,str2,判断两个字符串中出现的字符是否全部种类一样,数量一样。
例如:
str1 = “apple”, str2 = “paple”, 返回 True;
str1 = “pear”, str2 = “bears”, 返回 False。
ps: is 与 == 区别:
is 用于判断两个变量引用对象是否为同一个, == 用于判断引用变量的值是否相等。
'''
str1 ='apple'
str2 ='apple'if str1 == str2:print('true')else:print('false')'''
import hashlib
>>> a = 'adfd'
>>> b = 'adfd'
>>> c = 'addf'
>>> m = hashlib.md5(a.encode('utf-8'))
>>>
>>> m.hexdigest()
'84f57b4d03744d0bf803a1c9736c2b46'
>>>
>>> m = hashlib.md5(b.encode('utf-8'))
>>> m.hexdigest()
'84f57b4d03744d0bf803a1c9736c2b46'
>>> m = hashlib.md5(c.encode('utf-8'))
>>> m.hexdigest()
'240a8254415e3c29e645fb3fb4343bc0'
>>>
'''
5
'''
给定一个列表,判断其中所有的字符是不是都只出现过一次
'''import re
the_list =["abc","bcd",'efg','fgh','ijk','jk']
the_str =str(the_list)# 剔除数据
the_str = the_str.replace('[','')
the_str = the_str.replace(']','')all=set(the_str)# 所有不重复的元素
result1 =[]
result2 =[]for i inall:
res = the_str.count(i)if res ==1:
result1.append(i)print("count()结果:", result1)for i inall:if i !='['and i !=']':
res = re.findall(i, the_str)iflen(res)==1:
result2.append(i)print("re.findall结果:", result2)
6
'''
计算斐波那契数列。具体什么是斐波那契数列,那就是0,1,1,2,3,5,8,13,21,34,55,89,144,233。
'''deffib(max):'''
斐波拉契数列
:param max:
:return:
'''
n, a, b =0,0,1while n <max:yield b
a, b = b, a + b
n = n +1return'done'if __name__ =="__main__":
res =[]for n in fib(6):
res.append(n)print(res)
7
'''
写一个方法,传入一个整型列表,计算其中不重复数字的个数并返回
'''deffun(a):'''
获取不重复的元素
:param a:
:return:
'''
aa =set(a)# 不重复的数据集
res =[]# 存放结果集for i in aa:if a.count(i)==1:# 元素出现次数为1
res.append(i)return res
if __name__ =="__main__":
a =[1,2,3,5,8,5,4,1,10,11,5]
res = fun(a)print(res)
8
'''
随机获取一个字符串列表中的字符串,求获取一千次的情况下,各字符串被随机到的次数。
'''
__author__ ='llf'import random
from collections import Counter
c = Counter()
ll =['a','b']for i inrange(1000):
a = random.choice(ll)
c[a]= c[a]+1print('结果:',type(c),dir(c), c)'''
<class 'collections.Counter'>
[
'clear', 'copy', 'elements', 'fromkeys', 'get', 'items',
'keys', 'most_common', 'pop', 'popitem', 'setdefault',
'subtract', 'update', 'values'
]
'''