zoukankan      html  css  js  c++  java
  • 简单数据结构

    • 排列组合

      import itertools
      ​
      # 排列:从m个元素中提取n个,所有可能就是排列(有顺序)
      # 当m等于n时的排列称为全排列
      # it = itertools.permutations([1, 2, 3], 3)
      # 组合:没有顺序的排列
      # it = itertools.combinations([1, 2, 3, 4], 2)
      # 笛卡尔乘积:多个序列中的元素组合
      # it = itertools.product([1, 2], [3, 4], [5, 6])
      # 上面多个相同序列的场景
      it = itertools.product([1, 2], repeat=3)
      ​
      print(it)
      for i in it:
          print(i)
      ​
      # 可以转换为列表
      # print(list(it1))
    • 计数器及双向队列

      from collections import Counter, deque
      ​
      # 统计序列中元素出现的次数
      c = Counter([1, 2, 3, 4, 1, 2, 3, 1, 2, 1])
      ​
      print(c)
      print(type(c))
      # 可以转换为字典
      print(dict(c))
      ​
      # 双向队列
      d = deque([1, 2, 3])
      ​
      # 右侧追加
      d.append(4)
      # 左侧添加
      d.appendleft(5)
      ​
      # 右侧弹出数据
      print(d.pop())
      # 左侧弹出数据
      print(d.popleft())
      ​
      # 右侧扩展
      d.extend(['a', 'b', 'c'])
      # 左侧扩展
      d.extendleft(['aa', 'bb', 'cc'])
      ​
      # 循环移动:正数表示向右移动,负数表示向左移动
      # d.rotate(1)
      d.rotate(-1)
      print(d)
      print(list(d))
    • 链表

      • 添加节点

      • 追加节点

      • 插入节点

      • 删除节点

  • 相关阅读:
    复杂网络研究的委员老师信息总合
    numpy读取本地数据和索引
    numpy数组的计算
    numpy数组的创建
    python画图的工具及网站
    matplotlib直方图
    matplotlib.legend()函数用法
    matplotlib条形图
    matplotlib散点图
    matplotlib折线图
  • 原文地址:https://www.cnblogs.com/542684416-qq/p/9807234.html
Copyright © 2011-2022 走看看