rule 发表于 2018-8-6 09:22:37

python笔记-set

  编码
  unicode,万国码,统一码,为每种语言的每个字符设定了统一并且唯一的二进制编码,满足跨平台、跨语言的文本转换;
  utf-8-8-bit Unicode Transformation Format,针对Unicode的可变长度字符编码
  ascii码:American Standard Code for Information Interchange,美国信息交换标准代码
GBK-汉字编码字符集
  哈希表-是根据关键码值(Key value)而直接进行访问的数据结构
  对象是有类创建的;
  类有多少方法,对象就有多少功能
  set集合,不允许重复的元素出现
  访问速度快,解决了重复问题
  创建:通过类来创建
  s1 = set()
  s1.add('aaa')
  print(s1)
  s1.add('ccc')
  print(s1)
  爬虫:请求页面,拿到源码,把元素拿过来,找商品名称,找价格
  爬虫有入口,找所有的链接,访问过就放set里面
  最后 判断set里有没有url就可以了;
  cmdb:采集硬件资产
  交集、差集
  s1 = set()
  s2 = set()
s3 = s1.difference(s2)
  s4 = s1.difference_update(s2)
  s5 = s1.symmetric_difference(s2)
  print(s3)
  print(s4)
  print(s5)
  collections系列,集合
  Counter 计数器,对字典类型补充,对值出现的次数的统计,继承了collection类
  a = collections.Counter('aaaafdsfdsfsdfds')
  print(a)
Counter({'a': 4, 'f': 4, 'd': 4, 's': 4})
  有序字典orderedDict
页: [1]
查看完整版本: python笔记-set