请任何人帮助我,我想根据用户输入创建一个邻接列表。所以对于以下用户输入 [英] Please can anybody help me, I want to create a adjacency list based on user input. So for the following user input

查看:69
本文介绍了请任何人帮助我,我想根据用户输入创建一个邻接列表。所以对于以下用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人帮助我,我想根据用户输入创建一个邻接列表。所以对于以下用户输入

Please can anybody help me, i want to create a adjacency list based on user input. so for the following user input

C-C-C-C
  |       | 
  C C
  | 
  C

它会输出



it would output

carbongraph = {"1":["2"], "2":["1","3","5"], "3":["2","4","6"], "4" :["3"], "5":["2","7"], "6":["3"], "7":["5"]}



,因为它从左到右,从上到下读取,就好像在读书一样



告诉我如何将C从1到7从左到右,从上到下编号,就好像读书一样,我会自己计算出其余部分。



有人请回答我,我已经被困了好几天了。



我尝试了什么:



我尝试过使用枚举但我不能过去如何绕过它。


as it reads from left to right, top to bottom as if reading a book

just tell me how to Number the C's from 1 to 7 rom left to right, top to bottom as if reading a book, i will figure the rest out myself.

somebody please answer me i have been stuck for days.

What I have tried:

I have tried using enumerate but i just cant get past how to get round it.

推荐答案

1-2-3-4
  | |
  5 6
  |
  7


这篇关于请任何人帮助我,我想根据用户输入创建一个邻接列表。所以对于以下用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆