1.检查两个给定列表是否含有重复元素
def check_repeat(lst):
return len(lst)==len(set(lst))
2.检测两个字符串是否含有互相换位置的字符
from collections import Counter
def change(first,second):
return Counter(first)==Counter(second)
change("abcd1","1adbc")
3.返回以字节为单位的字符串长度
def byte-size(string):
return(len(string.encode("utf-8")))
byte-size("Hello World")#11
4.查看内存的情况
import sys
var=30
print(sys.getsizeof(var)
5.重复打印字符串N次
n=2
s="I love python"
print(s*n)
6.将字符串每个词的首字母大写
s="i love python forever"
print(s.title())
7.利用range函数将列表分成指定大小的小块
from math import ceil
def chunk(lst,size):
return list(map(lambda x: lst[