• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python实现dict版图遍历示例

python实现dict版图遍历示例

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python中dict,python dict,python 3.0 dict keys,python list dict,python dict函数等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

class Graph():
    def __init__(self, V, E):
        self.V = V
        self.E = E
        self.visited = []
        self.dict = {}
        self.fd = open("input.txt")

    def initGraph(self):
        self.visited = [0 for i in range(self.V+1)]
        for i in range(self.E):
            f, t = map(int, self.fd.readline().split())
            #f, t = map(int, sys.stdin.readline().split())
            if self.dict.has_key(f)==False:
                l = []
                l.append(t)
                self.dict[f] = l
            else:
                l = self.dict[f]
                l.append(t)
                self.dict[f] = l

   
    def dfsGraph(self, src):
        self.visited[src] = 1
        print src ,
        if self.dict.get(src): #self.dict[src]会出现异常
            for u in self.dict[src]:
                if self.visited[u]==0:
                    self.dfsGraph(u)

graph = Graph(6, 10)
graph.initGraph()
graph.dfsGraph(1)
</div>

nput.txt

output:
</div>

您可能想查找下面的文章:

  • Python 提取dict转换为xml/json/table并输出的实现代码
  • python 字典(dict)按键和值排序
  • Python数据类型详解(四)字典:dict
  • 详解Python中dict与set的使用
  • python中字典dict常用操作方法实例总结
  • python使用点操作符访问字典(dict)数据的方法
  • python使用点操作符访问字典(dict)数据的方法
  • Python 字典dict使用介绍
  • Python中实现两个字典(dict)合并的方法
  • python进阶教程之词典、字典、dict

相关文章

  • Python实现脚本锁功能(同时只能执行一个脚本)
  • Python 变量类型及命名规则介绍
  • python中元类用法实例
  • python实现井字棋游戏
  • Python同时向控制台和文件输出日志logging的方法
  • Python实现抓取网页并且解析的实例
  • Python语言的面相对象编程方式初步学习
  • python中二维阵列的变换实例
  • Pycharm学习教程(3) 代码运行调试
  • Windows下Python的Django框架环境部署及应用编写入门

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python检测一个对象是否为字符串类的方法
    • Python入门篇之编程习惯与特点
    • 使用Python脚本将文字转换为图片的实例分享
    • Python随手笔记之标准类型内建函数
    • Python自动登录126邮箱的方法
    • 从零学Python之入门(五)缩进和选择
    • 在Python中编写数据库模块的教程
    • 基于python实现微信模板消息
    • Python爬虫代理IP池实现方法
    • 详解Python中的各种函数的使用

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有