Lekcja – Graf skierowany

V = [1, 2, 3, 4]
E = [(1,2), (1,3),(2,4),(3,4)]

# show nodes reachable from node start

start = 3

# for x, y in E:
#     if x == start:
#         print(y)

print([y for (x,y) in E if x == start])

Lab

V = ['Berlin', 'Paris', 'Rome', 'Madrid', 'Warsaw', 'Praque', 'Wien']
E = [ ('Madrid', 'Paris'),
      ('Paris', 'Berlin'),
      ('Berlin', 'Warsaw'),
      ('Warsaw','Praque'),
      ('Praque', 'Wien'),
      ('Wien', 'Rome'),
      ('Berlin', 'Wien'),
      ('Rome', 'Praque'),
      ('Praque', 'Warsaw')
]

# What can be next step when starting in Berlin?
for start, stop in E:
    if start == 'Berlin':
        print(stop)

print([stop for (start, stop) in E if start == 'Berlin'])

# To travel to Warsaw I can start my trip in...
for start, stop in E:
    if stop == 'Warsaw':
        print(start)

print([start for (start, stop) in E if stop == 'Warsaw'])