-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaily_code.py
More file actions
65 lines (49 loc) · 1.39 KB
/
Copy pathDaily_code.py
File metadata and controls
65 lines (49 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# def capitalize_name(full_name):
# # Split the full name into words
# words = full_name.split()
# # Capitalize the first alphabetic character of each word if it exists
# capitalized_words = []
# for word in words:
# if word: # Check if the word is not empty
# # Capitalize the first character if it's alphabetic
# capitalized_word = word[0].upper() + word[1:] if word[0].isalpha() else word
# capitalized_words.append(capitalized_word)
# # Join the capitalized words back into a single string
# capitalized_name = ' '.join(capitalized_words)
# return capitalized_name
# # Input
# full_name = input().strip()
# # Output
# print(capitalize_name(full_name))
# def solve(s):
# li=s.split()
# l1=[]
# for i in li:
# if i[0].isalpha:
# j=i.title()
# l1.append(j)
# else:
# l1.append(i)
# s1=" ".join(l1)
# return s1
# s=input()
# solve(s)
from collections import deque
def bfs(graph,start):
visited = set()
queue = deque([start])
result = []
while queue:
node = queue.popleft()
if node not in visited:
visited.add(node)
result.append(node)
queue.extend(graph[node])
return result
graph = {
'A' : ['B' , 'C'] ,
'B' : ['E' , 'F'] ,
'C' : ['G'] ,
'E' : ['G']
}
print(bfs(graph,0))