isinstance(var, type)
如判断类型是否为字符串
>>> string = 'this is a string'
>>> isintance(string, str)
True
data = sorted(data, key = lambda e: e.__getitem__('count'))
反向排序(从高到低)
data = sorted(data, key = lambda e: e.__getitem__('count'), reverse = True)
output_list = sum(input_list, [])
def flatten(input_list):
output_list = []
while True:
if input_list == []:
break
for index, i in enumerate(input_list):
if isinstance(i, list):
input_list = i + input_list[index+1:]
break
else:
output_list.append(i)
input_list.pop(index)
break
return output_list
将文本字符串#指令内容#操作码#操作数
按#
分隔为几个部分,可能会产生空字符串,需要过滤掉,可以采用filter函数
list(filter(lambda x: x != '', text.split('#')))
dic = dict(zip(dic.values(), dic.keys()))