Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using visited as a default arg in graph and adding more deque use cases#1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sbalasa wants to merge2 commits intocodophobia:main
base:main
Choose a base branch
Loading
fromsbalasa:main
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -315,6 +315,53 @@ deque([4, 3, 1, 2])
2
4
'''

# To fetch last n values only

last_5 = deque(maxlen=5)

for i in range(1, 10+1):
last_5.append(i)

'''
deque([6, 7, 8, 9, 10], maxlen=5)
6
7
8
9
10
'''

# To rotate n times or -n times

country = deque(list("America"))

country.rotate(2)
print(country)
country.rotate(-3)
print(country)

'''
deque(['c', 'a', 'A', 'm', 'e', 'r', 'i'])
c
a
A
m
e
r
i

deque(['m', 'e', 'r', 'i', 'c', 'a', 'A'])
m
e
r
i
c
a
A
'''


```

## Queue
Expand DownExpand Up@@ -662,10 +709,9 @@ graph = defaultdict(list)
graph[1].append(2) # 1 -> 2
graph[2].append(3) # 1 -> 2 -> 3
graph[4].append(1) # 4 -> 1 -> 2 -> 3


visited = set()

def dfs(node, graph, visited):
def dfs(node, graph, visited=set()):
if node not in visited:
print(node)
visited.add(node)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp