11 2019 档案

摘要:使用 按位与运算符(&) 将能更加快速地判断一个整数是奇数还是偶数 使用举例如下: def check_number(n): if n & 1: return '奇数' else: return '偶数' # 简单测试: for i in range(-3, 3): print(i, check_n 阅读全文
posted @ 2019-11-12 19:32 Alan_LJP 阅读(1334) 评论(0) 推荐(0)
摘要:推荐4种方法 方法一:extend L = [1, 2, 3] List_1 = [] List_1.extend(L) print('List_1 =', List_1) 解释:新建一个空List,然后将L中所有的元素用extend的方法放入List_1中 方法二:切片 L = [1, 2, 3] 阅读全文
posted @ 2019-11-11 12:33 Alan_LJP 阅读(3523) 评论(0) 推荐(0)
摘要:针对于python 3.5以上版本: 最好的最快的最优雅的方法是: result_dict = {**dict_1, **dict_2} 例如:( dict 代表 dictionary,也就是字典) dict_1 = {1: 1, 2: 2} dict_2 = {3: 3, 4: 4} # 更新 d 阅读全文
posted @ 2019-11-11 11:42 Alan_LJP 阅读(3895) 评论(0) 推荐(0)
摘要:代码 不使用递归且不引入标准库,单纯用两个for循环即可得出一个list的所有子集 LIST = [1, 2, 3, 4] LEN_LIST = len(LIST) lst = [[]] for i in range(LEN_LIST): # 固定的值 for j in range(len(lst) 阅读全文
posted @ 2019-11-10 18:35 Alan_LJP 阅读(1885) 评论(0) 推荐(1)