简述Python的深浅拷贝?
将列表内的元素,根据位数合并成字典 lst = [1,2,4,8,16,32,64,128,256,512,1024,32769,65536,4294967296] # 输出 { 1:[1,2,3,8], 2:[16,32,64], 3:[128,256,512], 4:[1024,], 5:[32769,65536], 6:[4294967296] } list = [1,2,4,8,16,32,64,128,256,512,1024,32769,65536,4294967296] dict={} for i in list: dict.setdefault(len(str(i)),[]).append(i) print(dict) ###源码解析 def setdefault(self, *args, **kwargs): # real signature unknown """ Insert key with a value of default if key is not in the dictionary. Return the value for key if key is in the dictionary, else default. """ pass ###
一行999
print(' '.join([' '.join(['%s*%s=%-2s' % (y, x, x*y) for y in range(1, x+1)]) for x in range(1, 10)]))
#自叹不如
自己最开始研究的
f'{f'{i}*{j}={i*j}' for j in range(1,i+1)}' for i in range(1,10)