1、列表推导式 列表推导式生成列表对象,语法如下: [ 表达式 for item in 可迭代对象] 或者 [ 表达式 for item in 可迭代对象 if 条件判断] >>> [x*2 for x in range(1,5)][2, 4, 6, 8]>>> [x*2 for x in rang Read More
posted @ 2020-01-01 22:21 清风0815 Views(265) Comments(0) Diggs(0)
编写循环时,遵循下面三个原则可以大大提高运行效率,避免不需要的低效计算: 1、尽量减少循环内部不必要的计算 2、嵌套循环中,尽量减少内层循环的计算,尽可能的将计算往外层提 3、局部变量查询较快,尽量使用局部变量。 其他优化手段: 1、连接多个字符串时,使用join()而不使用+(因为+会产生新的字符 Read More
posted @ 2020-01-01 21:50 清风0815 Views(1627) Comments(0) Diggs(0)
1、字典的创建 (1)通过{}和dict()创建字典 >>> a = {'name':'gjr','age':32,'job':'dataAnalysize'}>>> b = dict(name='gjr',age=32,job='dataAnalyze')>>> a{'name': 'gjr', Read More
posted @ 2020-01-01 21:05 清风0815 Views(732) Comments(0) Diggs(0)
1、修改原始列表,不建新列表的排序 直接调用列表的sort()方法进行排序 >>> id(a)2864146375752>>> a.sort()>>> a[5, 10, 20, 30]>>> id(a)2864146375752 >>> a.sort(reverse=True)>>> a[30, 2 Read More
posted @ 2020-01-01 19:47 清风0815 Views(1841) Comments(0) Diggs(0)