Search code examples
pythongraphpyscripter

input a graph's edges


import sys
import itertools
nodes=input("enter the number of nodes")

q=[]

q.append(x)

r=0
vertices=[]
a=0

for i in xrange(0,nodes):
    vertices.append(a)
    a=a+1

def inputgraph():
    cordinates=[]
    cor1=input("enter x or -1 to exit:    ")

    while cor1!=-1:
        cor2= input("enter y")
        cordinates.append((cor1,cor2))
        cor1= input("enter x or -1 to exit:    ")

    return cordinates

def main():
    cordinates=inputgraph()

if __name__ == '__main__':
    main()

This is my python code to input the edges of a graph into a list. here we have to enter the edge (x,y) as two separate inputs. is there any way to input it as one input??


Solution

  • cor1, cor2 = [int(x) for x in raw_input("enter x y: ").split()]