Python
Dxigui_
这个作者很懒,什么都没留下…
展开
-
在 Windows 下把网页写入文件时报 `UnicodeEncodeError: 'gbk' codec can't encode character '\xba' ` 错误
在 Windows 下用爬虫将网页爬取并存到文件里时,出现编码错误在 Windows 下用爬虫爬取某个页面,当把该页面写入到本地的文件中时,会出现TypeError: write() argument must be str, not bytes 的错误,这是因为直接从目标服务器上获取的内容是 bytes 类型,而文件写入需要是 str 类型,所以需要对获取的内容进行解码.例如:...原创 2018-08-22 20:32:28 · 445 阅读 · 0 评论 -
Python 在列表循环中的一些坑
循环内用 remove 删除列表自身元素问题在 for i in list 循环中,如果在循环内部使用 list 的 remove 方法删除多个相邻的数据时,会出现漏删和输出信息错误; 当删除一个数据时,会出现输出信息错误。例如:# 创建一个 L list# 删除相邻的多个数据In [12]: L = [11, 22, 33, 44, 55, 66, 77]In [1...原创 2018-08-21 18:44:54 · 4723 阅读 · 0 评论 -
Python3 中内置函数 range() 用法扩展
Python 中内置函数 range() 用法扩展首先 range 他是一个不可变的数字序列,通常被用于需要循环的特定次数的循环中,它的返回值是一个 range 对象.>>> range(10)range(0, 10)>>> type(range(10))<class 'range'>range 函数可以接收 3 个参数,sta...原创 2018-08-21 18:55:37 · 695 阅读 · 0 评论 -
Python3 中深拷贝和浅拷贝
深拷贝和浅拷贝在 Python 中通常将值赋值个某个变量时,实际上是这个值的内存地址指向了该变量,变量就相当是这个值的内存地址的一个引用. 例如:>>> L = [11, 22, 33, 44, 55]>>> new_L = L>>> new_L[11, 22, 33, 44, 55]>>> L.append...原创 2018-08-21 19:19:20 · 313 阅读 · 0 评论 -
Leetcode 806.Number of Lines To Write String
806.Number of Lines To Write StringWe are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the widt...原创 2018-09-03 20:21:41 · 126 阅读 · 0 评论 -
Leetcode 747.Largest Number At Least Twice of Others
747. Largest Number At Least Twice of OthersIn a given integer array nums, there is always exactly one largest element.Find whether the largest element in the array is at least twice as much as ev...原创 2018-09-03 20:23:08 · 163 阅读 · 0 评论 -
Leetcode 561.Array Partition I
561. Array Partition IGiven an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1...原创 2018-09-03 20:30:20 · 169 阅读 · 0 评论 -
Python 内置函数系列之 abs(x)
Python 内置函数 abs(x)abs(x) 函数可以接收整数,浮点数和复数.当传入的参数是整数和浮点数时,abs(x) 函数返回该参数的绝对值,如果传入的参数时复数,返回的参数是该复数的大小.传入一个整数integer = -5print('%d 的绝对值是 %d' % (integer, abs(integer)))输出:-5 的绝对值是 5传入一个浮点型...原创 2018-09-06 17:18:37 · 1987 阅读 · 0 评论 -
Python 内置函数之 all(iterable)
注意 Python 版本是 Python 3.5内置函数 all(iterable)all(iterable) 函数接收一个可迭代对象,如果这个迭代对象中的每个元素都为 True 时或者这个迭代对象是空时返回 True,否者返回 False.iterable : 参数可以是一个 list, tuple, dict, str 等iterable 为 list, tu...原创 2018-09-06 18:57:53 · 1119 阅读 · 0 评论