Implement a function to find the intersection of two lists.
def intersection(list1, list2):
return list(set(list1) & set(list2))
Example:
復習用に保存
復習用に保存
この項目をブックマークに追加したり、難しい内容としてマークしたり、復習セットに入れたりできます。
WithoutBook は、分野別の面接質問、オンライン練習テスト、チュートリアル、比較ガイドをひとつのレスポンシブな学習空間にまとめています。
Python Coding の人気面接質問と回答を確認し、新卒者や経験者が就職面接の準備を進められます。
Python Coding の人気面接質問と回答を確認し、新卒者や経験者が就職面接の準備を進められます。
質問を検索して回答を確認できます。
def intersection(list1, list2):
return list(set(list1) & set(list2))
Example:
この項目をブックマークに追加したり、難しい内容としてマークしたり、復習セットに入れたりできます。
import numpy as np
matrix1 = np.array([[1, 2], [3, 4]])
matrix2 = np.array([[5, 6], [7, 8]])
result = np.dot(matrix1, matrix2)
Example:
この項目をブックマークに追加したり、難しい内容としてマークしたり、復習セットに入れたりできます。
def fibonacci_generator():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
Example:
この項目をブックマークに追加したり、難しい内容としてマークしたり、復習セットに入れたりできます。
def dfs(graph, node, visited):
if node not in visited:
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(graph, neighbor, visited)
Example:
この項目をブックマークに追加したり、難しい内容としてマークしたり、復習セットに入れたりできます。
class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def is_balanced(root):
if root is None:
return True
left_height = height(root.left)
right_height = height(root.right)
return abs(left_height - right_height) <= 1 and is_balanced(root.left) and is_balanced(root.right)
def height(node):
if node is None:
return 0
return max(height(node.left), height(node.right)) + 1
Example:
この項目をブックマークに追加したり、難しい内容としてマークしたり、復習セットに入れたりできます。
from collections import OrderedDict
class LRUCache:
def __init__(self, capacity):
self.cache = OrderedDict()
self.capacity = capacitydef get(self, key):
if key in self.cache:
self.cache.move_to_end(key)
return self.cache[key]
return -1def put(self, key, value):
if len(self.cache) >= self.capacity:
self.cache.popitem(last=False)
self.cache[key] = value
self.cache.move_to_end(key)
Example:
この項目をブックマークに追加したり、難しい内容としてマークしたり、復習セットに入れたりできます。