index
int64 | repo_name
string | branch_name
string | path
string | content
string | import_graph
string |
|---|---|---|---|---|---|
9,640
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/maximum_subarray.py
|
class Solution(object):
# time: O(N), space: O(N)
def maximum_subarray(self, arr):
if not arr:
return 0
result = arr[0]
dp = [arr[0]]
for i in range(1, len(arr)):
dp.append(arr[i] + max(dp[i - 1], 0)) # longest subarray until index i
result = max(result, dp[i])
return result
# time: O(N), space: O(1)
def maximum_subarray2(self, arr):
if not arr:
return 0
result = arr[0]
max_ending_here = arr[0]
for i in range(1, len(arr)):
max_ending_here = arr[i] + max(max_ending_here, 0)
result = max(result, max_ending_here)
return result
test_arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
solution = Solution()
print(solution.maximum_subarray2(test_arr))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,641
|
aymane081/python_algo
|
refs/heads/master
|
/dynamicProgramming/buy_sell_stock1.py
|
class Solution:
def get_max_profit(self, prices):
if not prices:
return 0
max_profit, max_here = 0, 0
for i in range(1, len(prices)):
max_here = max(max_here + prices[i] - prices[i - 1], 0)
max_profit = max(max_profit, max_here)
return max_profit
def get_max_profit2(self, prices):
if not prices:
return 0
buy, sell = float('-inf'), 0
for price in prices:
buy = max(buy, - price)
sell = max(sell, price + buy)
return sell
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,642
|
aymane081/python_algo
|
refs/heads/master
|
/trees/second_minimum_binary_tree.py
|
#671
from utils.treeNode import TreeNode
class Solution:
def second_minimum(self, root):
if not root:
return -1
level = [root]
curr_min = root.value
while level:
next_level = []
for node in level:
if node.left:
next_level.append(node.left)
next_level.append(node.right)
candidates = [node.value for node in next_level if node.value > curr_min]
if candidates:
return min(candidates)
level = next_level
return -1
# one = TreeNode(2)
# two = TreeNode(2)
# three = TreeNode(5)
# four = TreeNode(5)
# five = TreeNode(7)
# one.left = two
# one.right = three
# three.left = four
# three.right = five
one = TreeNode(2)
two = TreeNode(2)
three = TreeNode(2)
one.left = two
one.right = three
print(one)
print('=========')
solution = Solution()
print(solution.second_minimum(one))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,643
|
aymane081/python_algo
|
refs/heads/master
|
/dynamicProgramming/partition_equal_subset_sum.py
|
class Solution:
def can_partition(self, nums):
sum_nums = sum(nums)
if sum_nums % 2:
return False
target = sum_nums // 2
nums.sort(reverse = True) #Try the largest numbers first, since less operations to reach the target
subset_sum = [True] + [False for _ in range(target)]
for num in nums:
for i in range(target - 1, -1, -1): # Try the largest sums first
if num + i <= target and subset_sum[i]:
if i + num == target:
return True
subset_sum[num + i] = True
return False
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,644
|
aymane081/python_algo
|
refs/heads/master
|
/trees/complete_tree_nodes_count.py
|
class Solution:
def count_nodes(self, node):
if not node:
return 0
left_depth, right_depth = self.get_depth(node.left), self.get_depth(node.right)
if left_depth == right_depth:
#left side is complete
return 2 ** (left_depth) + self.count_nodes(node.right)
else:
# right side is complete
return 2 ** (right_depth) + self.count_nodes(node.left)
def get_depth(self, node):
depth = 0
while node:
depth += 1
node = node.left
return depth
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,645
|
aymane081/python_algo
|
refs/heads/master
|
/utils/graph.py
|
from collections import defaultdict
class Vertex:
def __init__(self, key):
self.id =key
self.connectedTo = {}
def add_neighbor(self, nbr, weight = 0):
self.connectedTo[nbr] = weight
def __str__(self):
return str(self.id) + ' connectedTo: ' + str([x.id for x in self.connectedTo])
def get_connections(self):
return self.connectedTo.keys()
def get_id(self):
return self.id
def get_weight(self, nbr):
return self.connectedTo[nbr]
class Graph:
def __init__(self):
self.vert_list = defaultdict(set)
def add(self, node1, node2):
self.vert_list[node1].add(node2)
self.vert_list[node2].add(node1)
def get_vertices(self):
return self.vert_list.keys()
def __iter__(self):
return iter(self.vert_list.keys())
def is_connected(self, node1, node2):
return node2 in self.vert_list[node1] and node1 in self.vert_list[node2]
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,646
|
aymane081/python_algo
|
refs/heads/master
|
/graphs/pacific_atlantic.py
|
from utils.matrix import Matrix
class Solution:
def pacific_atlantic(self, matrix):
if not matrix or not matrix[0]:
return []
rows, cols = len(matrix), len(matrix[0])
pacific, atlantic = set(), set()
for row in range(rows):
atlantic.add((row, cols - 1))
pacific.add((row, 0))
for col in range(cols):
atlantic.add((rows - 1, col))
pacific.add((0, col))
for ocean in [atlantic, pacific]:
frontier = set(ocean)
while frontier:
new_frontier = set()
for row, col in frontier:
for dir_r, dir_c in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
new_row, new_col = row + dir_r, col + dir_c
if new_row < 0 or new_row >= rows or new_col < 0 or new_col >= cols or (new_row, new_col) in ocean:
continue
if matrix[new_row][new_col] >= matrix[row][col]:
new_frontier.add((new_row, new_col))
frontier = new_frontier
ocean |= frontier
return list(atlantic & pacific)
def pacific_atlantic2(self, matrix):
"""
type matrix: Matrix
rtype: List([int, int])
"""
if not matrix or not matrix.rows_count or matrix.cols_count:
raise Exception('Invalid Matrix')
reached_cells = [[0 for _ in range(matrix.rows_count)] for _ in range(matrix.cols_count)]
pacific_queue = []
atlantic_queue = []
for row in range(matrix.rows_count):
pacific_queue.append((row, 0))
atlantic_queue.append((row, matrix.rows_count - 1))
reached_cells[row][0] += 1
reached_cells[row][matrix.rows_count - 1] += 1
for col in range(matrix.cols_count):
pacific_queue.append((0, col))
atlantic_queue.append((col, matrix.rows_cols - 1))
reached_cells[0][col] += 1
reached_cells[row][matrix.rows_cols - 1] += 1
self.bfs(pacific_queue, matrix, pacific_queue[:], reached_cells)
self.bfs(atlantic_queue, matrix, atlantic_queue[:], reached_cells)
return [[row, col] for row in range(matrix.rows_count) for col in range(matrix.cols_count) if reached_cells[row][col] == 2]
def bfs(self, queue, matrix, visited, reached_cells):
while queue:
new_queue = []
for (row, col) in queue:
for dir_r, dir_c in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
new_row, new_col = row + dir_r, col + dir_c
if not matrix.is_valid_cell(new_row, new_col) or (new_row, new_col) in visited or matrix[row][col] > matrix[new_row][new_col]:
continue
new_queue.append((new_row, new_col))
matrix[new_row][new_col] += 1
queue = new_queue
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,647
|
aymane081/python_algo
|
refs/heads/master
|
/next_right_pointer2.py
|
class Solution:
def connect(self, node):
if not node:
return
level = [node]
while level:
prev = None
next_level = []
for node in level:
if prev:
prev.next = node
prev = node
if node.left:
next_level.append(node.left)
if node.right:
next_level.append(node.right)
level = next_level
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,648
|
aymane081/python_algo
|
refs/heads/master
|
/dynamicProgramming/coin_change.py
|
class Solution:
def coin_change(self, coins, amount):
if amount < 1:
return -1
memo = [0 for _ in range(amount)]
return self.helper(coins, amount, memo)
def helper(self, coins, amount, memo):
if amount < 0:
return -1
if amount == 0:
return 0
if memo[amount - 1]:
return memo[amount - 1]
min_count = float('inf')
for coin in coins:
res = self.helper(coins, amount - coin, memo)
if res >= 0 and res < min_count:
min_count = res
memo[amount - 1] = -1 if min_count == float('inf') else 1 + min_count
return memo[amount - 1]
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,649
|
aymane081/python_algo
|
refs/heads/master
|
/trees/binary_tree_zigzag_level_order.py
|
from utils.treeNode import TreeNode
from utils.treeUtils import generate_tree
class Solution:
def get_zigzag_level_order(self, node):
result = []
if not node:
return result
should_reverse = False
level_nodes = [node]
while level_nodes:
result.append([])
new_level_nodes = []
for node in level_nodes:
result[-1].append(node.value)
if node.left:
new_level_nodes.append(node.left)
if node.right:
new_level_nodes.append(node.right)
level_nodes = new_level_nodes
if should_reverse:
result[-1] = result[-1][::-1]
should_reverse = not should_reverse
return result
root = generate_tree()
print(root)
solution = Solution()
print(solution.get_zigzag_level_order(root))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,650
|
aymane081/python_algo
|
refs/heads/master
|
/linkedList/swap_nodes_in_pair.py
|
#24
from utils.listNode import ListNode
class Solution:
def swap_pairs(self, head):
if not head:
return None
dummy = prev = ListNode(None)
while head and head.next:
next_head = head.next.next
prev.next = head.next
head.next.next = head
prev = head
head = next_head
prev.next = head
return dummy.next
one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
four = ListNode(4)
one.next = two
two.next = three
three.next = four
print(one)
solution = Solution()
print(solution.swap_pairs(one))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,651
|
aymane081/python_algo
|
refs/heads/master
|
/trees/add_one_row_to_tree.py
|
# 623
from utils.treeNode import TreeNode
# time: O(N)
# space: O(N) or the max number of node at each level
class Solution:
def add_row(self, root, v, d):
if d == 1:
new_root = TreeNode(v)
new_root.left = root
return new_root
current_level = [root]
while d > 2:
d -= 1
new_level = []
for node in current_level:
if node.left:
new_level.append(node.left)
if node.right:
new_level.append(node.right)
current_level = new_level
# current_level is at d - 1
for node in current_level:
node.left, node.left.left = TreeNode(v), node.left
node.right, node.right.right = TreeNode(v), node.right
return root
# one = TreeNode(1)
# two = TreeNode(2)
# three = TreeNode(3)
# four = TreeNode(4)
# five = TreeNode(5)
# six = TreeNode(6)
# four.left = two
# four.right = six
# two.left = three
# two.right = one
# six.left = five
one = TreeNode(1)
two = TreeNode(2)
three = TreeNode(3)
four = TreeNode(4)
five = TreeNode(5)
six = TreeNode(6)
four.left = two
# four.right = six
two.left = three
two.right = one
# six.left = five
print(four)
print('==============')
solution = Solution()
print(solution.add_row(four, 1, 3))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,652
|
aymane081/python_algo
|
refs/heads/master
|
/trees/tree_from_preorder_inorder.py
|
from utils.treeUtils import TreeNode
class Solution:
def build_tree(self, pre_order, in_order):
if not pre_order:
return None
return self.helper(0, 0, len(in_order) - 1, pre_order, in_order)
def helper(self, pre_start, in_start, in_end, pre_order, in_order):
if pre_start > len(pre_order) - 1 or in_start > in_end:
return None
value = pre_order[pre_start]
in_order_index = in_order.index(value)
root = TreeNode(value)
root.left = self.helper(pre_start + 1, in_start, in_order_index - 1, pre_order, in_order)
root.right = self.helper(pre_start + 1 + in_order_index - in_start, in_order_index + 1, in_end, pre_order, in_order)
return root
in_order = [4, 2, 5, 1, 3, 6, 7]
pre_order = [1, 2, 4, 5, 3, 6, 7]
solution = Solution()
print(solution.build_tree(pre_order, in_order))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,653
|
aymane081/python_algo
|
refs/heads/master
|
/strings/basic_calculator.py
|
class Solution(object):
# O(n) time and space
def basic_calculator(self, expression):
if not expression:
return
stack = []
num = 0
operation = '+'
for i, c in enumerate(expression):
if c.isdigit():
num = num * 10 + int(c)
if i == len(expression) - 1 or (not c.isdigit() and c != ' '): # c is operator or end of string
if operation == '+':
stack.append(num)
elif operation == '-':
stack.append(-num)
elif operation == '*':
stack.append(stack.pop() * num)
elif operation == '/':
left = stack.pop()
stack.append(left // num)
if left // num < 0 and left % num != 0:
stack[-1] += 1 # negative integer division result with remainder rounds down by default
num = 0 # num has been used, so reset
operation = c
return sum(stack)
solution = Solution()
print(solution.basic_calculator('1 + 2 * 3 - 4'))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,654
|
aymane081/python_algo
|
refs/heads/master
|
/linkedList/add_two_numbers.py
|
# 445
from utils.listNode import ListNode
class Solution:
def add(self, head1, head2):
num1 = self.listToInt(head1)
num2 = self.listToInt(head2)
return self.intToList(num1 + num2)
def listToInt(self, head):
result = 0
if not head:
return result
while head:
result = (result * 10) + head.value
head = head.next
return result
def intToList(self, num):
dummy = prev = ListNode(None)
for c in str(num):
prev.next = ListNode(int(c))
prev = prev.next
return dummy.next
class Solution2:
def add(self, head1, head2):
rev1, rev2 = self.reverse(head1), self.reverse(head2)
carry = 0
total_head = total_tail = ListNode(None)
while rev1 or rev2:
total = carry
if rev1:
total += rev1.value
rev1 = rev1.next
if rev2:
total += rev2.value
rev2 = rev2.next
total_tail.next = ListNode(total % 10)
carry = total // 10
total_tail = total_tail.next
if carry:
total_tail.next = ListNode(carry)
return self.reverse(total_head.next)
def reverse(self, head):
if not head:
return head
rev = None
while head:
rev, rev.next, head = head, rev, head.next
return rev
one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
four = ListNode(4)
five = ListNode(5)
six = ListNode(6)
seven = ListNode(7)
one.next = two
two.next = three
three.next = four
five.next = six
six.next = seven
print(one)
print(five)
solution = Solution2()
print(solution.add(one, five))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,655
|
aymane081/python_algo
|
refs/heads/master
|
/trees/bst_iterator.py
|
from utils.treeNode import TreeNode
class BSTIterator:
# O(n) worst case for time and space
def __init__(self, root):
self.stack = []
while root:
self.stack.append(root)
root = root.left
# O(1) time and space
def has_next(self):
return len(self.stack) > 0
#time: O(n) worst case, O(1) average
# space: O(n) worst case, O(log n) if balanced
def next(self):
if not self.has_next():
return None
node = self.stack.pop()
result = node.value
if node.right:
node = node.right
while node:
self.stack.append(node)
node = node.left
return result
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,656
|
aymane081/python_algo
|
refs/heads/master
|
/binarySearch/search_insert_position.py
|
class Solution:
def get_insert_position(self, nums, value):
left, right = 0, len(nums) - 1
# left <= right because we want the first occurrence of left > right, aka, left is bigger than value
while left <= right:
mid = (left + right) // 2
if mid == value:
return mid
if mid < value:
left = mid + 1
else:
right = mid - 1
return left
def get_insert_position2(self, nums, value):
left, right = 0, len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] > value:
right = mid - 1
else:
left = mid + 1
return left
nums = [1, 2, 3, 3, 5, 8]
solution = Solution()
print(solution.get_insert_position2(nums, 8))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,657
|
aymane081/python_algo
|
refs/heads/master
|
/trees/path_sum2.py
|
from utils.treeNode import TreeNode
class Solution:
def get_paths_sum(self, node, target):
result = []
if not node:
return result
self.get_paths_helper([], target, node, result)
return result
def get_paths_helper(self, path, target, node, result):
if not node:
return
target -= node.value
path.append(node.value)
if target == 0 and not node.left and not node.right:
result.append(path[:]) # import to add a new copy of path, because path will change
self.get_paths_helper(path, target, node.left, result)
self.get_paths_helper(path, target, node.right, result)
path.pop()
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,658
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/subsets.py
|
class Solution:
# Time: O(2 ** n), space(n * 2**n)
def generate_subsets_from_unique(self, nums):
result = []
self.backtrack(nums, [], 0, result)
return result
def generate_subsets_from_duplicates(self, nums):
result = []
nums.sort()
self.backtrack(nums, [], 0, result)
return result
def backtrack(self, nums, prefix, start, result):
result.append(prefix)
for i in range(start, len(nums)):
if i > start and nums[i] == nums[i-1]:
continue
self.backtrack(nums, prefix + [nums[i]], i + 1, result)
solution = Solution()
nums = [1,2,3]
# nums = [1,2,2]
print(solution.generate_subsets_from_unique(nums))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,659
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/four_way.py
|
# time: O(n ** 3)
class Solution:
ELEMENTS_COUNT = 4
def four_way(self, nums, target):
results = []
self.n_way(sorted(nums), target, [], self.ELEMENTS_COUNT, results)
return results
def n_way(self, nums, target, partial, n, results):
if len(nums) < n or nums[0] * n > target or nums[-1] * n < target:
return
if n == 2:
left, right = 0, len(nums)
while left < right:
if nums[left] + nums[right] == target:
results.append(partial + [nums[left], nums[right]])
left += 1
right -= 1
while nums[right] == nums[right + 1] and right > left:
right -= 1
while nums[left] == nums[left - 1] and left < right:
left += 1
elif nums[left] + nums[right] < target:
left += 1
else:
right -= 1
else:
# add the next element in the list to partial, in order to get to 2-sum
for i in range(len(nums) - n + 1):
if i == 0 or nums[i] != nums[i - 1]: # avoid dups if possible
self.n_way(nums[i + 1 :], target - nums[i], partial + [nums[i]], n - 1, results)
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,660
|
aymane081/python_algo
|
refs/heads/master
|
/linkedList/insertion_sort_list.py
|
# 147
from utils.listNode import ListNode
# time: O(N ** 2)
# space: O(1)
class Solution:
def insert_sort_list(self, head):
sorted_tail = dummy = ListNode(float('-inf'))
dummy.next = head
while sorted_tail.next:
node = sorted_tail.next
if node.value >= sorted_tail.value:
sorted_tail = sorted_tail.next
continue
sorted_tail.next = node.next
insertion = dummy
while insertion.next.value <= node.value:
insertion = insertion.next
node.next = insertion.next
insertion.next = node
return dummy.next
one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
four = ListNode(4)
one.next = two
two.next = three
three.next = four
print(one)
solution = Solution()
print(solution.insert_sort_list(one))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,661
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/find_duplicate.py
|
class Solution:
def get_duplicate(self, nums):
if not nums:
return
slow = nums[0]
fast = nums[slow] # which is nums[nums[0]]
while slow != fast:
slow = nums[slow]
fast = nums[nums[fast]]
fast = 0
while slow != fast:
slow = nums[slow]
fast = nums[fast]
return fast
nums = [1, 3, 2, 4, 3]
solution = Solution()
print(solution.get_duplicate(nums))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,662
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/min_cost_climbing_stairs.py
|
# 746
class Solution:
def min_cost(self, costs):
one_before, two_before = costs[1], costs[0]
for i in range(2, len(costs)):
one_before, two_before = min(one_before, two_before) + costs[i], one_before
return min(one_before, two_before)
solution = Solution()
costs = [10, 15, 20]
# costs = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
print(solution.min_cost(costs))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,663
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/two_sum_sorted_array.py
|
class Solution(object):
def two_sum(self, numbers, target):
"""
:type numbers: List[int]
:type target: int
:rtype: Tuple(int)
"""
left, right = 0, len(numbers) - 1
while left < right:
pair_sum = numbers[left] + numbers[right]
if pair_sum == target:
return (left + 1, right + 1)
elif pair_sum < target:
left += 1
else:
right -= 1
solution = Solution()
numbers = [1, 4, 8, 10, 18]
print(solution.two_sum(numbers, 12))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,664
|
aymane081/python_algo
|
refs/heads/master
|
/trees/flatten_binary_tree.py
|
from utils.treeNode import TreeNode
from utils.treeUtils import generate_tree
class Solution:
def __init__(self):
self.prev = None
def flatten(self, node):
if not node:
return None
self.prev = node
self.flatten(node.left)
temp = node.right
node.right = node.left
node.left = None
self.prev.right = temp
self.flatten(self.prev.right)
root = generate_tree()
print(root)
print('==============')
solution = Solution()
solution.flatten(root)
print(root)
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,665
|
aymane081/python_algo
|
refs/heads/master
|
/trees/find_bottom_left_value.py
|
# 513
from utils.treeNode import TreeNode
# time: O(N)
# space: O(N)
class Solution:
def find_bottom_left_value(self, root):
level = [root]
most_left = None
while level:
most_left = level[0].value
new_level = []
for node in level:
if node.left:
new_level.append(node.left)
if node.right:
new_level.append(node.right)
level = new_level
return most_left
one = TreeNode(1)
two = TreeNode(2)
three = TreeNode(3)
four = TreeNode(4)
five = TreeNode(5)
six = TreeNode(6)
seven = TreeNode(7)
one.left = five
five.left = three
five.right = four
one.right = two
two.right = six
# six.right = seven
print(one)
print('===========')
solution = Solution()
print(solution.find_bottom_left_value(one))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,666
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/remove_element.py
|
class Solution(object):
def remove_element(self, arr, val):
if not arr:
return 0
j = 0
for i in range(len(arr)):
if arr[i] != val:
arr[j] = arr[i]
j += 1
for i in range(len(arr) - j):
arr.pop()
return j
solution = Solution()
arr = [1, 2, 3, 2, 4, 5]
print(solution.remove_element(arr, 2))
print(arr)
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,667
|
aymane081/python_algo
|
refs/heads/master
|
/dynamicProgramming/ugly_number.py
|
class Solution:
def get_ugly_number(self, n, primes):
if n <= 0:
return 0
if n == 1:
return 1
uglys = [1]
indices = [0 for _ in range(len(primes))]
candidates = primes[:]
while len(uglys) < n:
ugly = min(candidates)
uglys.append(ugly)
# increment the correct indexes to avoid duplicates, and set the new candidates
for i in range(len(indices)):
if candidates[i] == ugly:
indices[i] += 1
candidates[i] = uglys[indices[i]] * primes[i]
return uglys[-1]
solution = Solution()
primes = [2, 3, 5]
print(solution.get_ugly_number(11, primes))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,668
|
aymane081/python_algo
|
refs/heads/master
|
/trees/unique_bst.py
|
class Solution:
def get_unique_bst_count(self, n):
if n <= 0:
return 0
return self.get_unique_bst_count_rec(1, n)
def get_unique_bst_count_rec(self, start, end):
if start >= end:
return 1
result = 0
for i in range(start, end + 1):
left_count = self.get_unique_bst_count_rec(start, i - 1)
right_count = self.get_unique_bst_count_rec(i + 1, end)
result += left_count * right_count
return result
def get_unique_bst_count2(self, n):
memo = [-1 for _ in range(n + 1)]
memo[0], memo[1] = 1, 1
return self.helper(n, memo)
def helper(self, n, memo):
if memo[n] != -1:
return memo[n]
count = 0
for i in range(n):
# how many ways can i distribute n - 1 nodes between left and right
count += self.helper(i, memo) * self.helper(n - 1 - i, memo)
return count
solution = Solution()
print(solution.get_unique_bst_count2(3))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,669
|
aymane081/python_algo
|
refs/heads/master
|
/graphs/network_delay_time.py
|
from collections import defaultdict
class Solution:
def networkDelayTime(self, times, K):
graph = self.build_graph(times)
dist = { node: int('float') for node in graph }
def dfs(node, elapsed):
if elapsed >= dist[node]:
return
dist[node] = elapsed
for time, nbr in sorted(graph[node]): # start with the node with the smallest travel time, as it has more chances of reaching all the nodes quicker
dfs(nbr, elapsed + time)
dfs(K, 0)
ans = max(dist.values())
return ans if ans != float('inf') else -1
def build_graph(self, times):
graph = defaultdict(list)
for u, v, w in times:
graph[u].append((w, v))
return graph
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,670
|
aymane081/python_algo
|
refs/heads/master
|
/trees/tree_from_postorder_inorder.py
|
from utils.treeNode import TreeNode
class Solution:
def build_tree(self, in_order, post_order):
if not in_order:
return None
return self.build(len(post_order) - 1, 0, len(in_order) - 1, in_order, post_order)
def build(self, post_end, in_start, in_end, in_order, post_order):
if post_end < 0 or in_start > in_end:
return None
value = post_order[post_end]
in_index = in_order.index(value)
root = TreeNode(value)
root.right = self.build(post_end - 1, in_index + 1, in_end, in_order, post_order)
root.left = self.build(post_end - 1 - in_end + in_index, in_start, in_index - 1, in_order, post_order)
return root
in_order = [4, 2, 5, 1, 3, 6, 7]
post_order = [4, 5, 2, 7, 6, 3, 1]
solution = Solution()
print(solution.build_tree(in_order, post_order))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,671
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/unique_paths2.py
|
import unittest
class Solution:
def get_unique_paths_count(self, matrix):
row_count, col_count = len(matrix), len(matrix[0])
if row_count == 0 or col_count == 0:
raise Exception('Unvalid Matrix')
if matrix[0][0] or matrix[-1][-1]:
return 0
row_paths = [0 for _ in range(col_count)]
path_count = 0
for row in range(row_count):
new_row_paths = []
for col in range(col_count):
if row == 0 and col == 0:
path_count = 1
elif matrix[row][col] == 1:
path_count = 0
else:
path_count = row_paths[col]
path_count += new_row_paths[-1] if col > 0 else 0
new_row_paths.append(path_count)
row_paths = new_row_paths
return row_paths[-1]
def uniquePathsWithObstacles(self, grid):
"""
:type obstacleGrid: List[List[int]]
:rtype: int
"""
if grid[0][0] or grid[-1][-1]:
return 0
m, n = len(grid), len(grid[0])
ways = [0] * (n + 1)
ways[1] = 1
for row in range(1, m + 1):
new_ways = [0]
for col in range(1, n + 1):
if grid[row - 1][col - 1] == 1:
new_ways.append(0)
else:
new_ways.append(new_ways[-1] + ways[col])
ways = new_ways
return ways[-1]
class Test(unittest.TestCase):
test_data = [([[0,0,0], [0,1,0], [0,0,0]], 2), ([[0,0,0], [1,0,1], [0,0,0]], 1)]
def test_get_unique_paths_count(self):
solution = Solution()
for data in self.test_data:
actual = solution.uniquePathsWithObstacles(data[0])
self.assertEqual(actual, data[1])
if __name__ == '__main__':
unittest.main()
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,672
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/find_minimum_rotated_sorted_arary.py
|
class Solution:
def get_minimum(self, nums):
left, right = 0, len(nums) - 1
while left < right:
if nums[left] <= nums[right]: # sorted array, return nums[left]
break
mid = (left + right) // 2
if nums[mid] < nums[left]: # min is either mid the left side of mid
right = mid
else: # nums[mid] >= nums[left] > num[right] => mid is not min
left = mid + 1
return nums[left]
solution = Solution()
# nums = [3, 4, 5, 6, 7, 1, 2]
# nums = [1, 2, 3, 4, 5, 6]
nums = [7, 8, 1, 2, 3, 4, 5, 6]
print(solution.get_minimum(nums))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,673
|
aymane081/python_algo
|
refs/heads/master
|
/linkedList/palindrome_linked_list.py
|
# 234
from utils.listNode import ListNode
class Solution:
def is_palindrome(self, head):
if not head:
return False
rev, slow, fast = None, head, head
while fast and fast.next:
fast = fast.next.next
rev, rev.next, slow = slow, rev, slow.next
if fast:
slow = slow.next
while rev and rev.value == slow.value:
rev = rev.next
slow = slow.next
return not rev
one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
four = ListNode(4)
five = ListNode(3)
six = ListNode(2)
seven = ListNode(1)
one.next = two
two.next = three
three.next = four
four.next = five
five.next = six
six.next = seven
print(one)
solution = Solution()
print(solution.is_palindrome(one))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,674
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/rotate_array.py
|
class Solution(object):
# O(N) time and space
def rotate_array(self, numbers, k):
"""
:type numbers: List[int]
:type k: int
:rtype: List[int]
"""
n = len(numbers)
if k > n:
raise ValueError('The array is not long enough to be rotated')
return numbers[n - k:] + numbers[:n - k]
# O(N) time, O(1) time
def rotate_array2(self, numbers, k):
"""
:type numbers: List[int]
:type k: int
:rtype: List[int]
"""
n = len(numbers)
if k > n:
raise ValueError('The array is not long enough')
self.reverse(numbers, 0, n - 1)
self.reverse(numbers, 0, k - 1)
self.reverse(numbers, k, n - 1)
def reverse(self, numbers, left, right):
while left < right:
numbers[left], numbers[right] = numbers[right], numbers[left]
left += 1
right -= 1
solution = Solution()
# print(solution.rotate_array([1,2,3,4,5,6,7], 1))
numbers = [1,2,3,4,5,6,7]
solution.rotate_array2(numbers, 3)
print(numbers)
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,675
|
aymane081/python_algo
|
refs/heads/master
|
/trees/left_leaves_sum.py
|
from utils.treeNode import TreeNode
class Solution:
#O(N) time, O(1) space
def get_left_leaves_sum(self, node):
result = 0
if not node:
return result
if node.left and not node.left.left and not node.left.right:
result += node.left.value
else:
result += self.get_left_leaves_sum(node.left)
result += self.get_left_leaves_sum(node.right)
return result
node1 = TreeNode(1)
node2 = TreeNode(2)
node3 = TreeNode(3)
node4 = TreeNode(4)
node5 = TreeNode(5)
node6 = TreeNode(6)
node7 = TreeNode(7)
node1.left = node2
node1.right = node3
node2.left = node4
node2.right = node5
node3.left = node6
node6.left = node7
print(node1)
solution = Solution()
print(solution.get_left_leaves_sum(node1))
def left_leaves_sum(root):
if not root:
return 0
result = 0
if root.left and not root.left.left and not root.left.right:
result += root.left.value
result += left_leaves_sum(root.left) + left_leaves_sum(root.right)
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,676
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/minimum_size_subarray_sum.py
|
class Solution:
def get_min_length(self, nums, target):
"""
type nums: List[int]
type target: int
:rtype : int
"""
min_length, sum_so_far, start = len(nums), 0, 0
for i, num in enumerate(nums):
sum_so_far += num
while sum_so_far - nums[start] >= target:
sum_so_far -= nums[start]
start += 1
min_length = min(min_length, i - start + 1)
return min_length if min_length < len(nums) else 0
solution = Solution()
nums = [2, 3, 1, 2, 4, 3]
print(solution.get_min_length(nums, 7))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,677
|
aymane081/python_algo
|
refs/heads/master
|
/arrays/missing_element.py
|
class Solution(object):
def missing_element(self, numbers):
"""
:type numbers: List[int]
:rtype: int
"""
n = len(numbers)
return (n * (n + 1) // 2) - sum(numbers)
solution = Solution()
numbers = [0, 2, 5, 3, 1]
print(solution.missing_element(numbers))
|
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/linkedList/odd_even_linked_list.py": ["/utils/listNode.py"], "/trees/binary_tree_pruning.py": ["/utils/treeNode.py"], "/linkedList/linked_list_components.py": ["/utils/listNode.py"], "/trees/path_sum.py": ["/utils/treeNode.py"], "/binarySearch/find_right_interval.py": ["/utils/interval.py"], "/trees/maximum_binary_tree.py": ["/utils/treeNode.py"], "/trees/diameter_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/reorder_list.py": ["/utils/listNode.py"], "/trees/binary_tree_from_sorted_array.py": ["/utils/treeNode.py"], "/trees/invert_binary_tree.py": ["/utils/treeNode.py"], "/trees/print_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/delete_node_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/maximum_square.py": ["/utils/matrix.py"], "/trees/binary_tree_paths.py": ["/utils/treeNode.py"], "/arrays/word_search.py": ["/utils/matrix.py"], "/linkedList/merge_two_sorted_lists.py": ["/utils/listNode.py"], "/arrays/search_matrix.py": ["/utils/matrix.py"], "/trees/maximum_width_binary_tree.py": ["/utils/treeNode.py"], "/linkedList/intersection_of_two_linked_list.py": ["/utils/listNode.py"], "/trees/substree_of_another_tree.py": ["/utils/treeNode.py"], "/linkedList/split_linked_list_in_parts.py": ["/utils/listNode.py"], "/trees/lowest_common_ancestor.py": ["/utils/treeNode.py"], "/graphs/number_of_islands.py": ["/utils/matrix.py"], "/trees/most_frequent_substree_sum.py": ["/utils/treeNode.py"], "/linkedList/rotate_list.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list2.py": ["/utils/listNode.py"], "/linkedList/partition_list.py": ["/utils/listNode.py"], "/trees/same_tree.py": ["/utils/treeNode.py"], "/trees/next_right_pointer.py": ["/utils/treeNode.py"], "/trees/path_sum3.py": ["/utils/treeNode.py"], "/trees/is_balanced.py": ["/utils/treeNode.py"], "/trees/unique_bst2.py": ["/utils/treeNode.py"], "/trees/binary_tree_level_order_traversal.py": ["/utils/treeNode.py"], "/trees/minimum_depth.py": ["/utils/treeNode.py"], "/trees/sum_root_to_leaf_numbers.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/binary_tree_side_view.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/arrays/merge_intervals.py": ["/utils/interval.py"], "/arrays/min_path_sum.py": ["/utils/matrix.py"], "/trees/binary_tree_inorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/preorder_traversal.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_largest_value_in_each_tree_row.py": ["/utils/treeNode.py"], "/graphs/dfs.py": ["/utils/graph.py"], "/trees/trim_binary_search_tree.py": ["/utils/treeNode.py"], "/linkedList/remove_duplicates2.py": ["/utils/listNode.py"], "/arrays/diagonal_traverse.py": ["/utils/matrix.py"], "/trees/symetric_tree.py": ["/utils/treeNode.py"], "/utils/treeUtils.py": ["/utils/treeNode.py"], "/linkedList/remove_linked_list_elements.py": ["/utils/listNode.py"], "/trees/second_minimum_binary_tree.py": ["/utils/treeNode.py"], "/graphs/pacific_atlantic.py": ["/utils/matrix.py"], "/trees/binary_tree_zigzag_level_order.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/linkedList/swap_nodes_in_pair.py": ["/utils/listNode.py"], "/trees/add_one_row_to_tree.py": ["/utils/treeNode.py"], "/trees/tree_from_preorder_inorder.py": ["/utils/treeUtils.py"], "/linkedList/add_two_numbers.py": ["/utils/listNode.py"], "/trees/bst_iterator.py": ["/utils/treeNode.py"], "/trees/path_sum2.py": ["/utils/treeNode.py"], "/linkedList/insertion_sort_list.py": ["/utils/listNode.py"], "/trees/flatten_binary_tree.py": ["/utils/treeNode.py", "/utils/treeUtils.py"], "/trees/find_bottom_left_value.py": ["/utils/treeNode.py"], "/trees/tree_from_postorder_inorder.py": ["/utils/treeNode.py"], "/linkedList/palindrome_linked_list.py": ["/utils/listNode.py"], "/trees/left_leaves_sum.py": ["/utils/treeNode.py"]}
|
9,682
|
tsurrdurr/MNIST-classification
|
refs/heads/master
|
/read_data.py
|
import fileinput
import struct
from sklearn.externals import joblib
root = "YOUR ROOT PATH ENDING WITH SLASH"
def main():
labels_path = root + "train-labels-idx1-ubyte.gz"
labels = get_labels(labels_path)
joblib.dump(labels, root + "labels.joblib.pkl")
images_path = root + "train-images-idx3-ubyte.gz"
images = get_grayscaled_images(images_path)
joblib.dump(images, root + "grayscaled_images_numeric.joblib.pkl")
def get_labels(labels_path):
print("Parsing labels...")
g = fileinput.FileInput(labels_path, openhook=fileinput.hook_compressed)
x = g.__next__()
head = []
for i in range(2):
head.append(struct.unpack(">I", x[4 * i:4 * i + 4])[0])
magic, n_labels = head
print("magic={}, labels={}".format(*head))
labels = []
j = 8 # byte index on current chunk
while len(labels) < n_labels:
try:
val = x[j]
except IndexError:
# read a new chunk from file
x = g.__next__()
j = 0
val = x[j]
labels.append(val)
j += 1
return labels
def get_grayscaled_images(images_path):
print("Parsing images...")
f = fileinput.FileInput(images_path, openhook=fileinput.hook_compressed)
x = f.__next__()
head = []
for i in range(4):
head.append(struct.unpack(">I", x[4*i:4*i+4])[0])
magic, n_images, rows, columns = head
print("magic={}, images={}, rows={}, cols={}".format(*head))
j = 16 # index in current chunk
images = []
for i in range(n_images):
img = [[0] * rows for i in range(columns)]
for r in range(rows):
for c in range(columns):
try:
val = x[j]
except IndexError:
# need to read a new chunk of data from file
x = f.__next__()
j = 0
val = x[j]
if val > 170:
img[r][c] = 2
elif val > 85:
img[r][c] = 1
else:
img[r][c] = 0
j+=1
images.append(img)
return images
if __name__ =='__main__':main()
|
{"/classification.py": ["/classifier_svc.py", "/classifier_sgd.py", "/classifier_nb.py", "/classifier_kn.py", "/read_data.py"], "/prediction.py": ["/read_data.py"]}
|
9,683
|
tsurrdurr/MNIST-classification
|
refs/heads/master
|
/classifier_kn.py
|
from sklearn.neighbors import KNeighborsClassifier
def classify(images, labels):
nbrs = KNeighborsClassifier(n_neighbors=3)
nbrs.fit(images, labels)
print("Accuracy: ", nbrs.score(images, labels))
return nbrs
|
{"/classification.py": ["/classifier_svc.py", "/classifier_sgd.py", "/classifier_nb.py", "/classifier_kn.py", "/read_data.py"], "/prediction.py": ["/read_data.py"]}
|
9,684
|
tsurrdurr/MNIST-classification
|
refs/heads/master
|
/classifier_nb.py
|
from sklearn.naive_bayes import MultinomialNB
def classify(images, labels):
mnb = MultinomialNB()
mnb.fit(images, labels)
print("Accuracy: ", mnb.score(images, labels))
return mnb
|
{"/classification.py": ["/classifier_svc.py", "/classifier_sgd.py", "/classifier_nb.py", "/classifier_kn.py", "/read_data.py"], "/prediction.py": ["/read_data.py"]}
|
9,685
|
tsurrdurr/MNIST-classification
|
refs/heads/master
|
/classifier_sgd.py
|
from sklearn.linear_model import SGDClassifier
def classify(images, labels):
clf = SGDClassifier(loss="hinge", penalty="l2")
clf.fit(images, labels)
print("Accuracy: ", clf.score(images, labels))
return clf
|
{"/classification.py": ["/classifier_svc.py", "/classifier_sgd.py", "/classifier_nb.py", "/classifier_kn.py", "/read_data.py"], "/prediction.py": ["/read_data.py"]}
|
9,686
|
tsurrdurr/MNIST-classification
|
refs/heads/master
|
/classifier_svc.py
|
from sklearn import svm
def classify(images, labels):
C = 1.0 # SVM regularization parameter
lin_svc = svm.LinearSVC(C=C)
lin_svc.fit(images, labels)
print("Accuracy: ", lin_svc.score(images, labels))
return lin_svc
|
{"/classification.py": ["/classifier_svc.py", "/classifier_sgd.py", "/classifier_nb.py", "/classifier_kn.py", "/read_data.py"], "/prediction.py": ["/read_data.py"]}
|
9,687
|
tsurrdurr/MNIST-classification
|
refs/heads/master
|
/classification.py
|
import numpy as np
import classifier_svc as SVC
import classifier_sgd as SGD
import classifier_nb as NB
import classifier_kn as KN
from sklearn.externals import joblib
from read_data import root
import sys
def main():
if sys.argv[1:]:
argument = sys.argv[1]
else:
argument = None
if(argument == "-svc"):
images, labels = read_data()
svc_classifier = SVC.classify(images, labels)
dump_classifier(svc_classifier)
elif(argument == "-sgd"):
images, labels = read_data()
sgd_classifier = SGD.classify(images, labels)
dump_classifier(sgd_classifier)
elif(argument == "-nb"):
images, labels = read_data()
nb_classifier = NB.classify(images, labels)
dump_classifier(nb_classifier)
elif(argument == "-kn"):
images, labels = read_data()
kn_classifier = KN.classify(images, labels)
dump_classifier(kn_classifier)
elif((argument == "-h") | (argument == "-help")):
print_help()
else:
print("Incorrect argument. Try \"-help\"")
def dump_classifier(classifier):
filename = root + "digits_classifier.joblib.pkl"
joblib.dump(classifier, filename)
def read_data():
print("Reading data to form a classifier...")
images = joblib.load(root + "grayscaled_images_numeric.joblib.pkl")
labels = joblib.load(root + "labels.joblib.pkl")
images = np.asanyarray(images)
images = images.reshape(60000, -60000)
print("Creating classifier...")
return images, labels
def print_help():
print("Possible arguments: \"-svc\", \"-sgd\", \"-nb\"")
print("\"-svc\" - use LinearSVC")
print("\"-sgd\" - use SGDClassifier")
print("\"-nb\" - use MultinomialNB")
print("\"-nn\" - use MultinomialNB")
if __name__ =='__main__':main()
|
{"/classification.py": ["/classifier_svc.py", "/classifier_sgd.py", "/classifier_nb.py", "/classifier_kn.py", "/read_data.py"], "/prediction.py": ["/read_data.py"]}
|
9,688
|
tsurrdurr/MNIST-classification
|
refs/heads/master
|
/prediction.py
|
import numpy as np
import read_data as reader
from sklearn.externals import joblib
from read_data import root
def normalize(image):
image = np.asanyarray(image)
image = image.reshape(10000, -10000)
return image
def main():
test_images_path = root + "t10k-images-idx3-ubyte.gz"
test_labels_path = root + "t10k-labels-idx1-ubyte.gz"
test_labels = reader.get_labels(test_labels_path)
test_images = reader.get_grayscaled_images(test_images_path)
print("Loading classifier...")
classifier_path = root + "digits_classifier.joblib.pkl"
classifier = joblib.load(classifier_path)
i = 0
match = 0
print("Predicting test samples classes...")
test_images = normalize(test_images)
result = classifier.predict(test_images)
while(i < 10000):
if(result[i] == test_labels[i]):
match += 1
i += 1
print("Matched: ", match)
if __name__ =='__main__':main()
|
{"/classification.py": ["/classifier_svc.py", "/classifier_sgd.py", "/classifier_nb.py", "/classifier_kn.py", "/read_data.py"], "/prediction.py": ["/read_data.py"]}
|
9,689
|
StefanM98/Project-Movie-Trailer-Website
|
refs/heads/master
|
/entertainment_center.py
|
import media
import fresh_tomatoes
# Create new instances of the Movie class for each movie
moana = media.Movie("Moana",
"https://upload.wikimedia.org/wikipedia/en/2/26/"
"Moana_Teaser_Poster.jpg",
"https://youtu.be/LKFuXETZUsI")
zootopia = media.Movie("Zootopia",
"https://upload.wikimedia.org/wikipedia/en/thumb/"
"e/ea/Zootopia.jpg/220px-Zootopia.jpg",
"https://youtu.be/jWM0ct-OLsM")
deadpool = media.Movie("Deadpool",
"https://upload.wikimedia.org/wikipedia/en/4/46/"
"Deadpool_poster.jpg",
"https://youtu.be/ONHBaC-pfsk")
dumb_and_dumber = media.Movie("Dumb and Dumber",
"https://images-na.ssl-images-amazon.com/"
"images/I/51XVZYDA0ZL.jpg",
"https://youtu.be/l13yPhimE3o")
walle = media.Movie("WALL-E",
"http://www.gstatic.com/tv/thumb/movieposters/"
"174374/p174374_p_v8_ab.jpg",
"https://youtu.be/vbLNOFbsRow")
# Place all our movies into an array
movies = [moana, zootopia, deadpool, dumb_and_dumber, walle]
# Pass the movies array to the open_movies_page function to create the page
fresh_tomatoes.open_movies_page(movies)
|
{"/entertainment_center.py": ["/media.py"]}
|
9,690
|
StefanM98/Project-Movie-Trailer-Website
|
refs/heads/master
|
/media.py
|
"""Define the Movie class which gives us the basic format of each
movie instance upon initalization."""
class Movie():
def __init__(self, movie_title, box_art, trailer_link):
self.title = movie_title
self.poster_image_url = box_art
self.trailer_youtube_url = trailer_link
|
{"/entertainment_center.py": ["/media.py"]}
|
9,725
|
abbass2/pyqstrat
|
refs/heads/master
|
/pyqstrat/notebooks/support/build_example_strategy.py
|
# type: ignore
# flake8: noqa
import pandas as pd
import numpy as np
import math
from types import SimpleNamespace
import pyqstrat as pq
def sma(contract_group, timestamps, indicators, strategy_context): # simple moving average
sma = pd.Series(indicators.c).rolling(window = strategy_context.lookback_period).mean()
return sma.values
def band(contract_group, timestamps, indicators, strategy_context, upper):
std = pd.Series(indicators.c).rolling(window = strategy_context.lookback_period).std()
return indicators.sma + strategy_context.num_std * std * (1 if upper else -1)
upper_band = lambda contract_group, timestamps, indicators, strategy_context : \
band(contract_group, timestamps, indicators, strategy_context, upper = True)
lower_band = lambda contract_group, timestamps, indicators, strategy_context : \
band(contract_group, timestamps, indicators, strategy_context, upper = False)
def bollinger_band_signal(contract_group, timestamps, indicators, parent_signals, strategy_context):
# Replace nans with 0 so we don't get errors later when comparing nans to floats
h = np.nan_to_num(indicators.h)
l = np.nan_to_num(indicators.l)
upper_band = np.nan_to_num(indicators.upper_band)
lower_band = np.nan_to_num(indicators.lower_band)
sma = np.nan_to_num(indicators.sma)
signal = np.where(h > upper_band, 2, 0)
signal = np.where(l < lower_band, -2, signal)
signal = np.where((h > sma) & (signal == 0), 1, signal) # price crossed above simple moving avg but not above upper band
signal = np.where((l < sma) & (signal == 0), -1, signal) # price crossed below simple moving avg but not below lower band
return signal
def bollinger_band_trading_rule(contract_group, i, timestamps, indicators, signal, account, current_orders, strategy_context):
timestamp = timestamps[i]
curr_pos = account.position(contract_group, timestamp)
signal_value = signal[i]
risk_percent = 0.1
close_price = indicators.c[i]
contract = contract_group.get_contract('PEP')
if contract is None:
contract = pq.Contract.create(symbol = 'PEP', contract_group = contract_group)
# if we don't already have a position, check if we should enter a trade
if math.isclose(curr_pos, 0):
if signal_value == 2 or signal_value == -2:
curr_equity = account.equity(timestamp)
order_qty = np.round(curr_equity * risk_percent / close_price * np.sign(signal_value))
trigger_price = close_price
reason_code = pq.ReasonCode.ENTER_LONG if order_qty > 0 else pq.ReasonCode.ENTER_SHORT
return [pq.StopLimitOrder(contract=contract, timestamp=timestamp, qty=order_qty, trigger_price=trigger_price, reason_code=reason_code)]
else: # We have a current position, so check if we should exit
if (curr_pos > 0 and signal_value == -1) or (curr_pos < 0 and signal_value == 1):
order_qty = -curr_pos
reason_code = pq.ReasonCode.EXIT_LONG if order_qty < 0 else pq.ReasonCode.EXIT_SHORT
return [pq.MarketOrder(contract=contract, timestamp=timestamp, qty=order_qty, reason_code=reason_code)]
return []
def market_simulator(orders, i, timestamps, indicators, signals, strategy_context):
trades = []
timestamp = timestamps[i]
for order in orders:
trade_price = np.nan
cgroup = order.contract.contract_group
ind = indicators[cgroup]
o, h, l, c = ind.o[i], ind.h[i], ind.l[i], ind.c[i]
if isinstance(order, pq.MarketOrder):
trade_price = 0.5 * (o + h) if order.qty > 0 else 0.5 * (o + l)
elif isinstance(order, pq.StopLimitOrder):
if (order.qty > 0 and h > order.trigger_price) or (order.qty < 0 and l < order.trigger_price): # A stop order
trade_price = 0.5 * (order.trigger_price + h) if order.qty > 0 else 0.5 * (order.trigger_price + l)
else:
raise Exception(f'unexpected order type: {order}')
if np.isnan(trade_price): continue
trade = pq.Trade(order.contract, order, timestamp, order.qty, trade_price, commission = order.qty * 5, fee = 0)
order.status = 'filled'
trades.append(trade)
return trades
def get_price(symbol, timestamps, i, strategy_context):
return strategy_context.c[i]
def build_example_strategy(strategy_context):
try:
file_path = os.path.dirname(os.path.realpath(__file__)) + '/../notebooks/support/pepsi_15_min_prices.csv.gz' # If we are running from unit tests
except:
file_path = '../notebooks/support/pepsi_15_min_prices.csv.gz'
prices = pd.read_csv(file_path)
prices.date = pd.to_datetime(prices.date)
timestamps = prices.date.values
pq.ContractGroup.clear()
pq.Contract.clear()
contract_group = pq.ContractGroup.create('PEP')
strategy_context.c = prices.c.values # For use in the get_price function
strategy = pq.Strategy(timestamps, [contract_group], get_price, trade_lag = 1, strategy_context = strategy_context)
strategy.add_indicator('o', prices.o.values)
strategy.add_indicator('h', prices.h.values)
strategy.add_indicator('l', prices.l.values)
strategy.add_indicator('c', prices.c.values)
strategy.add_indicator('sma', sma, depends_on = ['c'])
strategy.add_indicator('upper_band', upper_band, depends_on = ['c', 'sma'])
strategy.add_indicator('lower_band', lower_band, depends_on = ['c', 'sma'])
strategy.add_signal('bb_signal', bollinger_band_signal, depends_on_indicators = ['h', 'l', 'sma', 'upper_band', 'lower_band'])
# ask pqstrat to call our trading rule when the signal has one of the values [-2, -1, 1, 2]
strategy.add_rule('bb_trading_rule', bollinger_band_trading_rule,
signal_name = 'bb_signal', sig_true_values = [-2, -1, 1, 2])
strategy.add_market_sim(market_simulator)
return strategy
|
{"/pyqstrat/notebooks/support/build_example_strategy.py": ["/pyqstrat/__init__.py"]}
|
9,726
|
abbass2/pyqstrat
|
refs/heads/master
|
/pyqstrat/__init__.py
|
# flake8: noqa
# include functions for easy reference from pq prefix
from pyqstrat.pq_utils import *
from pyqstrat.pq_types import *
from pyqstrat.pq_io import *
from pyqstrat.holiday_calendars import *
from pyqstrat.markets import *
from pyqstrat.account import *
from pyqstrat.strategy import *
from pyqstrat.portfolio import *
from pyqstrat.optimize import *
from pyqstrat.plot import *
from pyqstrat.interactive_plot import *
from pyqstrat.evaluator import *
from pyqstrat.pyqstrat_cpp import *
from pyqstrat.pyqstrat_io import *
|
{"/pyqstrat/notebooks/support/build_example_strategy.py": ["/pyqstrat/__init__.py"]}
|
9,727
|
abbass2/pyqstrat
|
refs/heads/master
|
/setup.py
|
import setuptools
from Cython.Build import cythonize
from distutils.core import setup, Extension
import numpy as np
import pybind11
import glob
import os
import sys
if __name__ == '__main__':
_conda_prefix = os.getenv('CONDA_PREFIX')
_conda_prefix_1 = os.getenv('CONDA_PREFIX_1')
if _conda_prefix is None and _conda_prefix_1 is None:
raise RuntimeError("CONDA_PREFIX and CONDA_PREFIX_1 not found in env variables")
_windows = (sys.platform == "win32")
conda_prefix = _conda_prefix if _conda_prefix else _conda_prefix_1
pybind_11_include = [pybind11.get_include()]
np_include = [np.get_include()]
if sys.platform in ["win32", "cygwin"]:
include_dirs = [f'{conda_prefix}/include',
f'{conda_prefix}/Library/include']
library_dirs = [f'{conda_prefix}/lib',
f'{conda_prefix}/Library/lib',
f'{conda_prefix}/bin',
f'{conda_prefix}/Library/bin']
else:
include_dirs = [f'{conda_prefix}/lib']
library_dirs = [f'{conda_prefix}/lib']
extra_compile_args=[] if _windows else ['-std=c++11', '-Ofast']
cython_extra_compile_args=[] if _windows else ['-Wno-parentheses-equality', '-Wno-unreachable-code-fallthrough', '-Ofast']
cpp_dir = 'pyqstrat/cpp'
io_module = Extension('pyqstrat.pyqstrat_io',
sources = [f'{cpp_dir}/io/{file}' for file in ['read_file.cpp', 'csv_reader.cpp']],
include_dirs=include_dirs + np_include,
library_dirs=library_dirs,
libraries=['zip'],
extra_compile_args=extra_compile_args)
opt_cpp_files = glob.glob(f'{cpp_dir}/options/*.cpp') + glob.glob(f'{cpp_dir}/lets_be_rational/*.cpp')
options_module = Extension('pyqstrat.pyqstrat_cpp',
sources = opt_cpp_files,
include_dirs=include_dirs + pybind_11_include,
library_dirs=library_dirs,
extra_compile_args=extra_compile_args)
_compute_pnl_module = Extension('pyqstrat.compute_pnl',
['pyqstrat/compute_pnl.pyx'],
include_dirs=np_include,
extra_compile_args=cython_extra_compile_args,
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')])
compute_pnl_module = cythonize([_compute_pnl_module], compiler_directives={'language_level' : "3"})[0]
with open('version.txt', 'r') as f:
version = f.read().strip()
with open('requirements.txt', 'r') as f:
requirements = f.read().splitlines()
with open('README.rst', 'r') as f:
long_description=f.read()
setup(name='pyqstrat',
version=version,
ext_modules = [io_module, options_module, compute_pnl_module],
author_email='abbasi.sal@gmail.com',
url='http://github.com/abbass2/pyqstrat/',
license='BSD',
python_requires='>=3.10',
install_requires=requirements,
description='fast / extensible library for backtesting quantitative strategies',
long_description=long_description,
packages=['pyqstrat'],
include_package_data=True,
platforms='any',
classifiers = [
'Development Status :: 4 - Beta',
'Natural Language :: English',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Office/Business :: Financial :: Investment',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3 :: Only',
],
zip_safe = False)
|
{"/pyqstrat/notebooks/support/build_example_strategy.py": ["/pyqstrat/__init__.py"]}
|
9,750
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/admin.py
|
from django.contrib import admin
from .models import Comment
# Register your models here.
class CommentAdmin(admin.ModelAdmin):
list_display = ('comment', 'created_date', 'created_time')
fields = ('event', 'comment', 'created_by')
search_fields = ('comment',)
admin.site.register(Comment, CommentAdmin)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,751
|
Gigibit/ubildin
|
refs/heads/master
|
/apiv1/views.py
|
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import permissions, reverse, generics
# Create your views here.
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,752
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/migrations/0002_auto_20180508_0004.py
|
# Generated by Django 2.0.4 on 2018-05-08 00:04
import cloudinary.models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('userprofile', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='profile',
options={'verbose_name_plural': 'Profiles'},
),
migrations.AlterField(
model_name='profile',
name='photo',
field=cloudinary.models.CloudinaryField(max_length=255, verbose_name='image'),
),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,753
|
Gigibit/ubildin
|
refs/heads/master
|
/lib/python3.7/site-packages/filebrowser/compat.py
|
# coding: utf-8
def get_modified_time(storage, path):
if hasattr(storage, "get_modified_time"):
return storage.get_modified_time(path)
return storage.modified_time(path)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,754
|
Gigibit/ubildin
|
refs/heads/master
|
/events/migrations/0003_auto_20180424_1611.py
|
# Generated by Django 2.0.4 on 2018-04-24 16:11
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0002_auto_20180421_2218'),
]
operations = [
migrations.RenameField(
model_name='comment',
old_name='post',
new_name='comment',
),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,755
|
Gigibit/ubildin
|
refs/heads/master
|
/events/forms.py
|
from django import forms
from tinymce import TinyMCE
from .models import Event
class TinyMCEWidget(TinyMCE):
def use_required_attribute(self, *args):
return False
class EventForm(forms.ModelForm):
details = forms.CharField(
widget=TinyMCEWidget(
attrs={'required':False, 'cols':30, 'rows':10}
)
)
class Meta:
model = Event
fields = ('category', 'name', 'details', 'venue', 'time', 'date',)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,756
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/models.py
|
from django.db import models
from django.conf import settings
from django.shortcuts import reverse
from cloudinary.models import CloudinaryField
from events.models import Event
# Create your models here.
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
date_of_birth = models.DateField(blank=True, null=True)
photo = CloudinaryField('image', blank=True, null=True)
class Meta:
verbose_name_plural = 'profiles'
def __str__(self):
return '{0}\'s profile'.format(self.user.username)
def get_absolute_url(self):
return reverse('userprofile:detail', kwargs={'pk': self.pk})
def get_date_of_birth(self):
return self.date_of_birth
def is_attending(self):
if Event.objects.filter(pk=self.pk, attendees=self.user).exists():
return True
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,757
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/tests/test_views.py
|
from django.test import TestCase
from django.shortcuts import reverse
from events.models import Event, User, Category
from comments.models import Comment
class CommentDeleteViewTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.attendee = User.objects.create_user(username='tobi', password=56789)
self.attendee.save()
self.user.save()
self.category = Category.objects.create(name='Technology', description='This is the future')
self.event = Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
self.comment = Comment.objects.create(comment='Hey yo', event=self.event, created_by=self.user)
def test_delete_comment_url_exists_at_desired_location(self):
comment = Comment.objects.create(comment='Hey yo', event=self.event, created_by=self.user)
self.client.login(username='iyanu', password=12345)
response = self.client.get(reverse('comments:comment-delete', kwargs={'pk': self.comment.pk}))
# Check the user is logged in
# self.assertEqual(str(response.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('comments:comment-delete', kwargs={'pk': self.comment.pk}))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('comments:comment-delete', kwargs={'pk': self.comment.pk}))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'comments/delete.html')
def test_delete_view_redirect_to_event_detail_view(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('comments:comment-delete', kwargs={'pk': self.comment.pk}))
self.assertEqual(response.status_code, 200)
self.assertRedirects(response, self.event.get_absolute_url())
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,758
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/tests/test_models.py
|
from django.test import TestCase
from django.contrib.auth.models import User
from userprofile.models import Profile
class ProfileModelTest(TestCase):
@classmethod
def setUpTestData(cls):
user = User.objects.create(username='iyanu', password=12345, email='iyanu@gmail.com')
Profile.objects.create(user=user, date_of_birth='2018-05-18', photo='')
def test_user_label(self):
profile = Profile.objects.get(date_of_birth='2018-05-18')
field_label = profile._meta.get_field('user').verbose_name
self.assertEquals(field_label, 'user')
def test_date_of_birth_label(self):
profile = Profile.objects.get(date_of_birth='2018-05-18')
field_label = profile._meta.get_field('date_of_birth').verbose_name
self.assertEquals(field_label, 'date of birth')
def test_photo_label(self):
profile = Profile.objects.get(date_of_birth='2018-05-18')
field_label = profile._meta.get_field('photo').verbose_name
self.assertEquals(field_label, 'image')
def test_profile_object_name(self):
profile = Profile.objects.get(date_of_birth='2018-05-18')
expected_object_name = '{0}\'s profile'.format(profile.user.username)
self.assertEquals(expected_object_name, str(profile))
def test_get_absolute_url(self):
profile = Profile.objects.get(date_of_birth='2018-05-18')
self.assertEquals(profile.get_absolute_url(), '/userprofile/detail/8/')
def test_get_absolute_url_not_none(self):
profile = Profile.objects.get(date_of_birth='2018-05-18')
self.assertIsNotNone(profile.get_absolute_url())
def test_verbose_name_plural(self):
self.assertEquals(str(Profile._meta.verbose_name_plural), 'profiles')
def test_get_date_of_birth(self):
profile = Profile.objects.get(date_of_birth='2018-05-18')
self.assertEquals(profile.get_date_of_birth(), '2018, 5, 18')
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,759
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/urls.py
|
from django.urls import path
from . import views
app_name = 'userprofile'
urlpatterns = [
path('edit/', views.edit_profile, name='edit'),
path('detail/<int:pk>/', views.UserDetail.as_view(), name='detail'),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,760
|
Gigibit/ubildin
|
refs/heads/master
|
/events/tests/test_models.py
|
from django.test import TestCase
from events.models import Event, Category, User
class EventModelTest(TestCase):
@classmethod
def setUpTestData(cls):
category = Category.objects.create(name='Technology', description='This is the future')
user = User.objects.create(username='iyanu', password=12345, email='iyanu@gmail.com')
Event.objects.create(name='Party Outside', details='This party is gonna be banging again', venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=category, creator=user)
def test_name_label(self):
event = Event.objects.get(name='Party Outside')
field_label = event._meta.get_field('name').verbose_name
self.assertEquals(field_label, 'name')
def test_details_label(self):
event = Event.objects.get(name='Party Outside')
field_label = event._meta.get_field('details').verbose_name
self.assertEquals(field_label, 'Details')
def test_venue_label(self):
event = Event.objects.get(name='Party Outside')
field_label = event._meta.get_field('venue').verbose_name
self.assertEquals(field_label, 'venue')
def test_date_label(self):
event = Event.objects.get(name='Party Outside')
field_label = event._meta.get_field('date').verbose_name
self.assertEquals(field_label, 'date')
def test_time_label(self):
event = Event.objects.get(name='Party Outside')
field_label = event._meta.get_field('time').verbose_name
self.assertEquals(field_label, 'time')
def test_name_max_length(self):
event = Event.objects.get(name='Party Outside')
max_length = event._meta.get_field('name').max_length
self.assertEquals(max_length, 50)
def test_venue_max_length(self):
event = Event.objects.get(name='Party Outside')
max_length = event._meta.get_field('venue').max_length
self.assertEquals(max_length, 200)
def test_event_object_name(self):
event = Event.objects.get(name='Party Outside')
expected_object_name = '{}'.format(event.name)
self.assertEquals(expected_object_name, str(event))
def test_get_absolute_url(self):
event = Event.objects.get(name='Party Outside')
self.assertEquals(event.get_absolute_url(), '/events/13/')
def test_get_absolute_url_not_none(self):
event = Event.objects.get(name='Party Outside')
self.assertIsNotNone(event.get_absolute_url())
def test_get_number_of_attendees(self):
event = Event.objects.get(name='Party Outside')
self.assertEquals(event.get_number_of_attendees(), 0)
def test_get_comments_number(self):
event = Event.objects.get(name='Party Outside')
self.assertEquals(event.get_comments_number(), 0)
def test_verbose_name_plural(self):
self.assertEquals(str(Event._meta.verbose_name_plural), 'events')
class CategoryModelTest(TestCase):
@classmethod
def setUpTestData(cls):
Category.objects.create(name='Technology', description='This is the future')
def test_category_object_name(self):
category = Category.objects.get(name='Technology')
expected_object_name = '{}'.format(category.name)
self.assertEquals(expected_object_name, str(category))
def test_category_verbose_name_plural(self):
self.assertEquals(str(Category._meta.verbose_name_plural), 'categories')
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,761
|
Gigibit/ubildin
|
refs/heads/master
|
/events/migrations/0006_auto_20180425_1825.py
|
# Generated by Django 2.0.4 on 2018-04-25 18:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0005_auto_20180425_1727'),
]
operations = [
migrations.AlterField(
model_name='event',
name='details',
field=models.TextField(max_length=10000),
),
migrations.AlterField(
model_name='event',
name='time',
field=models.TimeField(help_text='Please use the following format: <em>HH:MM:SS<em>'),
),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,762
|
Gigibit/ubildin
|
refs/heads/master
|
/events/urls.py
|
from django.urls import path
from . import views
app_name = 'events'
urlpatterns = [
path('', views.EventList.as_view(), name='event-list'),
path('events/<int:pk>/', views.EventDetail.as_view(), name='event-detail'),
path('events/new/', views.EventCreate.as_view(), name='event-create' ),
path('events/<int:pk>/delete', views.EventDelete.as_view(), name='event-delete'),
path('events/<int:pk>/update', views.EventUpdate.as_view(), name='event-update'),
path('events/<event_id>/attend/', views.attend_event, name='attend_event'),
path('events/<event_id>/not_attend/', views.not_attend_event, name='not_attend_event'),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,763
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/tests/test_forms.py
|
from django.test import TestCase
from events.models import Category, Event, User
from userprofile.models import Profile
from comments.models import Comment
from comments.forms import CommentForm
class CommentFormTest(TestCase):
def setUp(self):
category = Category.objects.create(name='Technology', description='This is the future')
self.user = User.objects.create(username='iyanu', password=12345, email='iyanu@gmail.com')
self.event = Event.objects.create(name='Party Out', details='This party is gonna be banging', venue='Ibadan',
date='2018-06-18', time='12:00:00', category=category, creator=self.user)
Comment.objects.create(comment='Hey yo', event=self.event, created_by=self.user)
Profile.objects.create(date_of_birth='2018-12-12', user=self.user)
def test_comment_form_valid(self):
form = CommentForm(data={'comment': 'Hey yo'})
self.assertTrue(form.is_valid())
def test_comment_form_invalid(self):
form = CommentForm(
data={'comment': ''})
self.assertFalse(form.is_valid())
self.assertEqual(form.errors, {'comment': ['This field is required.']})
def test_comment_form_comment_field_label(self):
form = CommentForm()
self.assertTrue(form.fields['comment'].label == None or form.fields['comment'].label == 'Comment')
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,764
|
Gigibit/ubildin
|
refs/heads/master
|
/events/migrations/0001_initial.py
|
# Generated by Django 2.0.4 on 2018-04-21 15:39
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, unique=True)),
('description', models.TextField(max_length=500)),
],
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('post', models.TextField(max_length=500)),
('created_date', models.DateField(auto_now=True)),
('created_time', models.TimeField(auto_now=True)),
('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ('created_date', 'created_time'),
},
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('details', models.TextField(max_length=1000)),
('venue', models.CharField(max_length=50)),
('date', models.DateField(help_text='Please use the following format: <em>YYYY-MM-DD</em>.')),
('time', models.TimeField()),
('attendees', models.ManyToManyField(blank=True, related_name='attending', to=settings.AUTH_USER_MODEL)),
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='events.Category')),
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'events',
'verbose_name': 'event',
},
),
migrations.AddField(
model_name='comment',
name='event',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='events.Event'),
),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,765
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/migrations/0003_auto_20180516_1534.py
|
# Generated by Django 2.0.4 on 2018-05-16 15:34
import cloudinary.models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('userprofile', '0002_auto_20180508_0004'),
]
operations = [
migrations.AlterField(
model_name='profile',
name='photo',
field=cloudinary.models.CloudinaryField(blank=True, max_length=255, null=True, verbose_name='image'),
),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,766
|
Gigibit/ubildin
|
refs/heads/master
|
/events/templatetags/events_tags.py
|
from django import template
from ..models import Event
from comments.models import Comment
register = template.Library()
@register.simple_tag(name='total')
def total_attending():
pass
@register.simple_tag()
def total_comments():
return Comment.objects.count()
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,767
|
Gigibit/ubildin
|
refs/heads/master
|
/events/tests/test_views.py
|
from django.test import TestCase
from django.urls import reverse
from comments.models import Comment
from comments.forms import CommentForm
from events.models import Event, Category, User
class EventListViewTest(TestCase):
def setUp(self):
user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
user.save()
category = Category.objects.create(name='Technology', description='This is the future')
number_of_events = 15
for event_num in range(number_of_events):
Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=category, creator=user)
def test_view_url_exists_at_desired_location(self):
self.client.login(username='iyanu', password=12345)
resp = self.client.get('')
# Check the user is logged in
self.assertEqual(str(resp.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(resp.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
resp = self.client.get(reverse('events:event-list'))
self.assertEqual(resp.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
resp = self.client.get(reverse('events:event-list'))
self.assertEqual(resp.status_code, 200)
self.assertTemplateUsed(resp, 'events/list_of_events.html')
def test_pagination_is_ten(self):
self.client.login(username='iyanu', password='12345')
resp = self.client.get(reverse('events:event-list'))
self.assertEqual(resp.status_code, 200)
self.assertTrue('is_paginated' in resp.context)
self.assertTrue(resp.context['is_paginated'] == True)
self.assertTrue(len(resp.context['events']) == 10)
def test_list_all_events_on_second_page(self):
self.client.login(username='iyanu', password='12345')
resp = self.client.get(reverse('events:event-list') + '?page=2')
self.assertEqual(resp.status_code, 200)
self.assertTrue('is_paginated' in resp.context)
self.assertTrue(resp.context['is_paginated'] == True)
self.assertTrue(len(resp.context['events']) == 5)
class EventDetailViewTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.attendee = User.objects.create_user(username='tobi', password=56789)
self.attendee.save()
self.user.save()
self.category = Category.objects.create(name='Technology', description='This is the future')
self.event = Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
def test_detail_of_event(self):
self.client.login(username='iyanu', password=12345)
response = self.client.get(self.event.get_absolute_url())
# Check the user is logged in
self.assertEqual(str(response.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-detail', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-detail', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'events/detail.html')
def test_name_of_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(self.event.get_absolute_url())
self.assertContains(response, self.event.name, html=True)
def test_details_of_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(self.event.get_absolute_url())
self.assertContains(response, self.event.details, html=True)
def test_category_of_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(self.event.get_absolute_url())
self.assertEqual(self.category, self.event.category)
def test_creator_of_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(self.event.get_absolute_url())
self.assertContains(response, self.event.creator.username)
def test_list_attendees_for_a_detail_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-detail', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['attending'])
def test_list_of_comments_for_a_detail_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-detail', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
self.assertEquals(len(response.context['comments']), self.event.comments.all().count())
def test_comment_form_on_event_detail_page(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-detail', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['form'])
def test_create_comment_form_displays_comment_on_event_detail_page(self):
self.client.login(username='iyanu', password='12345')
comment = Comment.objects.create(comment='Wow, how far', created_by=self.user, event=self.event)
response = self.client.get(self.event.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Wow')
def test_valid_create_comment_form_on_event_detail_page_can_post_comment(self):
self.client.login(username='iyanu', password='12345')
response = self.client.post(self.event.get_absolute_url(),
data={'comment': 'Wow, how far tobi', 'event': 'self.event.pk',
'created_by': 'self.user'})
new_response = self.client.get(self.event.get_absolute_url())
self.assertEqual(new_response.status_code, 200)
self.assertEqual(Comment.objects.last().comment, 'Wow, how far tobi')
class EventCreateViewTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.attendee = User.objects.create_user(username='tobi', password=56789)
self.attendee.save()
self.user.save()
self.category = Category.objects.create(name='Technology', description='This is the future')
self.event = Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
def test_create_event_url_exists_at_desired_location(self):
self.client.login(username='iyanu', password=12345)
response = self.client.get('/events/new/')
# Check the user is logged in
self.assertEqual(str(response.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-create'))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-create'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'events/create_form.html')
def test_event_form_is_on_create_event_page(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-create'))
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['form'])
def test_create_event_form_displays_event_on_event_detail_page(self):
self.client.login(username='iyanu', password='12345')
event = Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
response = self.client.get(event.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'party is gonna')
def test_valid_create_event_form_on_can_post_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.post(reverse('events:event-create'),
data={'name': 'Party Outside', 'details': 'This party is gonna be banging again',
'venue': 'Mapo Hall', 'date': '2018-05-18', 'time': '12:25:00',
'category': self.category, 'creator': self.user})
new_response = self.client.get(self.event.get_absolute_url())
self.assertEqual(new_response.status_code, 200)
self.assertEqual(Event.objects.last().details, 'This party is gonna be banging again')
class EventUpdateViewTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.attendee = User.objects.create_user(username='tobi', password=56789)
self.attendee.save()
self.user.save()
self.category = Category.objects.create(name='Technology', description='This is the future')
self.event = Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
def test_update_event_url_exists_at_desired_location(self):
event = Event.objects.create(name='Google io', details='Android is coming for you',
venue='Google Plex',
date='2018-11-18', time='10:25:00', category=self.category, creator=self.user)
self.client.login(username='iyanu', password=12345)
response = self.client.get(reverse('events:event-update', kwargs={'pk': self.event.pk}))
# Check the user is logged in
# self.assertEqual(str(response.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-update', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-update', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'events/update_form.html')
def test_event_form_is_on_update_event_page(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-update', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['form'])
def test_valid_update_event_form_on_can_update_event(self):
self.client.login(username='iyanu', password='12345')
response = self.client.post(reverse('events:event-update', kwargs={'pk': self.event.pk}),
data={'name': 'Party Outside', 'details': 'This party is gonna be banging again',
'venue': 'Mapo Hall', 'date': '2018-05-18', 'time': '12:25:00',
'category': self.category, 'creator': self.user})
new_response = self.client.get(self.event.get_absolute_url())
self.assertEqual(new_response.status_code, 200)
self.assertEqual(Event.objects.last().details, 'This party is gonna be banging again')
class EventDeleteViewTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.attendee = User.objects.create_user(username='tobi', password=56789)
self.attendee.save()
self.user.save()
self.category = Category.objects.create(name='Technology', description='This is the future')
self.event = Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
def test_delete_event_url_exists_at_desired_location(self):
event = Event.objects.create(name='Google io', details='Android is coming for you',
venue='Google Plex',
date='2018-11-18', time='10:25:00', category=self.category, creator=self.user)
self.client.login(username='iyanu', password=12345)
response = self.client.get(reverse('events:event-delete', kwargs={'pk': self.event.pk}))
# Check the user is logged in
# self.assertEqual(str(response.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-delete', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('events:event-delete', kwargs={'pk': self.event.pk}))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'events/delete.html')
def test_delete_view_redirect_to_list_view(self):
self.client.login(username='iyanu', password='12345')
response = self.client.post(reverse('events:event-delete', kwargs={'pk': self.event.pk}))
# self.assertEqual(response.status_code, 200)
self.assertRedirects(response, '/')
class AttendEventTestView(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.attendee = User.objects.create_user(username='tobi', password=56789)
self.attendee.save()
self.user.save()
self.category = Category.objects.create(name='Technology', description='This is the future')
self.event = Event.objects.create(name='Party Outside', details='This party is gonna be banging again',
venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
def test_attend_event_url_exists_at_desired_location(self):
event = Event.objects.create(name='Google io', details='Android is coming for you',
venue='Google Plex',
date='2018-11-18', time='10:25:00', category=self.category, creator=self.user)
self.client.login(username='iyanu', password=12345)
response = self.client.post(reverse('events:attend_event', kwargs={'event_id': self.event.id}))
self.assertNotEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.post(reverse('events:attend_event', kwargs={'event_id': self.event.id}))
self.assertNotEqual(response.status_code, 200)
def test_attend_event_view_redirect_to_event_detail(self):
self.client.login(username='iyanu', password='12345')
response = self.client.post(reverse('events:attend_event', kwargs={'event_id': self.event.id}))
self.assertRedirects(response, reverse('events:event-detail', kwargs={'pk': self.event.pk}))
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,768
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/migrations/0004_auto_20180523_1407.py
|
# Generated by Django 2.0.4 on 2018-05-23 14:07
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('userprofile', '0003_auto_20180516_1534'),
]
operations = [
migrations.AlterModelOptions(
name='profile',
options={'verbose_name_plural': 'profiles'},
),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,769
|
Gigibit/ubildin
|
refs/heads/master
|
/lib/python3.7/site-packages/tests/models.py
|
from .test_base import *
from .test_commands import *
from .test_decorators import *
from .test_settings import *
from .test_sites import *
from .test_templatetags import *
from .test_versions import *
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,770
|
Gigibit/ubildin
|
refs/heads/master
|
/events/migrations/0008_auto_20180428_0831.py
|
# Generated by Django 2.0.4 on 2018-04-28 08:31
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0007_auto_20180427_2316'),
]
operations = [
migrations.AlterField(
model_name='event',
name='details',
field=models.TextField(max_length=1000),
),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,771
|
Gigibit/ubildin
|
refs/heads/master
|
/apiv1/urls.py
|
from django.urls import path, include
from rest_framework.urlpatterns import format_suffix_patterns
from rest_framework.routers import DefaultRouter
from . import viewsets
router = DefaultRouter()
router.register(r'events', viewsets.EventViewset)
router.register(r'comments', viewsets.CommentViewset)
router.register(r'category', viewsets.CategoryViewset)
router.register(r'profile', viewsets.ProfileViewset)
app_name = 'apiv1'
urlpatterns = [
path('', include(router.urls))
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,772
|
Gigibit/ubildin
|
refs/heads/master
|
/actions/views.py
|
from django.shortcuts import render
from django.views.generic import ListView
from .models import Action
# Create your views here.
class NotificationList(ListView):
model = Action
template_name = 'actions/notifications.html'
context_object_name = 'actions'
def get_queryset(self):
return Action.objects.exclude(user=self.request.user)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,773
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/views.py
|
from django.shortcuts import render
from django.views import generic
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from events.models import Event
from comments.models import Comment
from .forms import ProfileForm, UserForm
from .models import Profile
# Create your views here.
@login_required()
def edit_profile(request):
# This line is a part of the connection to Cloudinary API
context = dict(backend_form=ProfileForm())
if request.method == 'POST':
user_form = UserForm(instance=request.user, data=request.POST)
profile_form = ProfileForm(instance=request.user.profile, data=request.POST, files=request.FILES)
context['posted'] = profile_form.instance
if user_form.is_valid() and profile_form.is_valid():
user_form.save()
profile_form.save()
else:
# This creates a profile for users that don't have a profile.
# They didn't have a profile because they registered before the profile feature was added.
# A profile is created for a user during the process of signup.
Profile.objects.get_or_create(user=request.user)
user_form = UserForm(instance=request.user)
profile_form = ProfileForm(instance=request.user.profile)
return render(request, 'userprofile/update_form.html', {'user_form': user_form, 'profile_form': profile_form})
class UserDetail(LoginRequiredMixin, generic.DetailView):
model = User
template_name = 'userprofile/profile_detail.html'
context_object_name = 'user'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['events'] = Event.objects.filter(creator=self.request.user)
context['comments'] = Comment.objects.filter(created_by=self.request.user)
return context
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,774
|
Gigibit/ubildin
|
refs/heads/master
|
/events/models.py
|
from django.db import models
from django.conf import settings
from django.shortcuts import reverse
from django.contrib.auth.models import User
from tinymce import HTMLField
# Create your models here.
class Category(models.Model):
name = models.CharField(max_length=50, unique=True)
description = models.TextField(max_length=500)
class Meta:
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
class Event(models.Model):
name = models.CharField(max_length=50)
details = HTMLField('Details')
venue = models.CharField(max_length=200)
date = models.DateField(help_text='Please use the following format: <em>YYYY-MM-DD</em>.')
time = models.TimeField(help_text='Please use the following format: <em>HH:MM:SS<em>')
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='events')
creator = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
attendees = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='attending', blank=True)
num_of_attendees = models.PositiveIntegerField(default=0, blank=True)
class Meta:
verbose_name = 'event'
verbose_name_plural = 'events'
ordering = ['date', 'time']
def get_absolute_url(self):
return reverse('events:event-detail', kwargs={'pk': self.pk})
def __str__(self):
return self.name
def get_number_of_attendees(self):
return self.attendees.all().count()
def get_comments_number(self):
return self.comments.all().count()
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,775
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/forms.py
|
from django import forms
from .models import Comment
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('comment', 'parent')
widgets = {
'comment': forms.Textarea(attrs={'class': 'form-control'}),
'parent': forms.HiddenInput()
}
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,776
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/tests/test_forms.py
|
from django.test import TestCase
from django.contrib.auth.models import User
from userprofile.forms import ProfileForm
from userprofile.models import Profile
class ProfileFormTest(TestCase):
def setUp(self):
self.user = User.objects.create(username='iyanu', password=12345, email='iyanu@gmail.com')
Profile.objects.create(user=self.user, date_of_birth='2018-05-18', photo='')
def test_profile_form_valid(self):
form = ProfileForm(data={'user': 'self.user', 'date_of_birth': '2018-05-18', 'photo': ''})
self.assertTrue(form.is_valid())
def test_profile_form_date_of_birth_field_label(self):
form = ProfileForm()
self.assertTrue(form.fields['date_of_birth'].label == None or form.fields['date_of_birth'].label == 'Date of birth')
def test_profile_form_photo_field_label(self):
form = ProfileForm()
self.assertTrue(form.fields['photo'].label == None or form.fields['photo'].label == 'Image')
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,777
|
Gigibit/ubildin
|
refs/heads/master
|
/events/admin.py
|
from django.contrib import admin
from .models import Category, Event
# Register your models here.
class CategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'description')
fields = ('name', 'description')
admin.site.register(Category, CategoryAdmin)
class EventAdmin(admin.ModelAdmin):
list_display = ('name', 'venue', 'date', 'time')
fields = ('category', 'name', 'creator', 'details', 'venue', ('date', 'time'))
search_fields = ('name', 'details')
admin.site.register(Event, EventAdmin)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,778
|
Gigibit/ubildin
|
refs/heads/master
|
/apiv1/serializers.py
|
from rest_framework import serializers
from events.models import Category, Event, User
from comments.models import Comment
from userprofile.models import Profile
from actions.models import Action
class UserSerializer(serializers.HyperlinkedModelSerializer):
events = serializers.HyperlinkedRelatedField(many=True, view_name='event-detail', read_only=True)
class Meta:
model = User
fields = ('id', 'url', 'username', 'events')
class CommentSerializer(serializers.HyperlinkedModelSerializer):
event = serializers.HyperlinkedRelatedField(read_only=True, view_name='event-detail')
created_by = serializers.HyperlinkedRelatedField(read_only=True, view_name='comment-detail')
class Meta:
model = Comment
fields = ('id', 'url', 'comment', 'created_date', 'created_time', 'event', 'created_by')
class EventSerializer(serializers.HyperlinkedModelSerializer):
category = serializers.ReadOnlyField(source='category.name')
creator = serializers.HyperlinkedRelatedField(read_only=True, view_name='event-detail')
attendees = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='event-detail')
comments = CommentSerializer(read_only=True)
class Meta:
model = Event
fields = ('id', 'url', 'name', 'details', 'venue', 'date', 'time', 'category', 'creator',
'attendees', 'comments')
class CategorySerializer(serializers.HyperlinkedModelSerializer):
events = EventSerializer(read_only=True)
class Meta:
model = Category
fields = ('id', 'url', 'name', 'description')
class ProfileSerializer(serializers.HyperlinkedModelSerializer):
user = serializers.ReadOnlyField(source='user.username')
class Meta:
model = Profile
fields = ('id', 'url', 'user', 'date_of_birth', 'photo')
class ActionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Action
fields = ('id', 'url', 'user', 'verb', 'created')
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,779
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/urls.py
|
from django.urls import path
from . import views
app_name = 'comments'
urlpatterns = [
path('<int:pk>/delete/', views.CommentDelete.as_view(), name='comment-delete'),
path('<comment_id>/<event_id>/detail/', views.comment_detail, name='comment-detail'),
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,780
|
Gigibit/ubildin
|
refs/heads/master
|
/events/tests/test_forms.py
|
from django.test import TestCase
from events.forms import EventForm
from events.models import Event, Category, User
class EventFormTest(TestCase):
def setUp(self):
self.category = Category.objects.create(name='Technology', description='This is the future')
self.user = User.objects.create(username='iyanu', password=12345, email='iyanu@gmail.com')
Event.objects.create(name='Party Outside', details='This party is gonna be banging again', venue='Mapo Hall',
date='2018-05-18', time='12:25:00', category=self.category, creator=self.user)
def test_event_form_invalid(self):
form = EventForm(data={'name': '', 'details': '', 'venue': 'Mapo Hall',
'date': '2018-05-18', 'time': '12:25:00', 'category': 'category', 'creator': 'user'})
self.assertFalse(form.is_valid())
def test_event_form_date_field_label(self):
form = EventForm()
self.assertTrue(form.fields['date'].label == None or form.fields['date'].label == 'Date')
def test_event_form_date_field_help_text(self):
form = EventForm()
self.assertEqual(form.fields['date'].help_text, 'Please use the following format: <em>YYYY-MM-DD</em>.')
def test_event_form_time_field_label(self):
form = EventForm()
self.assertTrue(form.fields['time'].label == None or form.fields['time'].label == 'Time')
def test_event_form_time_field_help_text(self):
form = EventForm()
self.assertEqual(form.fields['time'].help_text, 'Please use the following format: <em>HH:MM:SS<em>')
def test_event_form_name_field_label(self):
form = EventForm()
self.assertTrue(form.fields['name'].label == None or form.fields['name'].label == 'Name')
def test_event_form_details_field_label(self):
form = EventForm()
self.assertTrue(form.fields['details'].label == None or form.fields['details'].label == 'Details')
def test_event_form_venue_field_label(self):
form = EventForm()
self.assertTrue(form.fields['venue'].label == None or form.fields['venue'].label == 'Venue')
def test_event_form_category_field_label(self):
form = EventForm()
self.assertTrue(form.fields['category'].label == None or form.fields['category'].label == 'Category')
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,781
|
Gigibit/ubildin
|
refs/heads/master
|
/events/templatetags/events_filters.py
|
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter(name='total_attendees')
def all_caps(text):
pass
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,782
|
Gigibit/ubildin
|
refs/heads/master
|
/apiv1/viewsets.py
|
from rest_framework import viewsets, permissions
from rest_framework.decorators import action
from rest_framework.response import Response
from .serializers import CategorySerializer, EventSerializer, CommentSerializer, ProfileSerializer, ActionSerializer
from events.models import Category, Event
from comments.models import Comment
from userprofile.models import Profile
from events.models import User
class CategoryViewset(viewsets.ReadOnlyModelViewSet):
"""
This provides list and retrieve actions
"""
queryset = Category.objects.all()
serializer_class = CategorySerializer
class EventViewset(viewsets.ModelViewSet):
"""
An authenticated user can list, retrieve, create, update, delete, and attend an event
"""
queryset = Event.objects.all()
serializer_class = EventSerializer
@action(detail=True)
def attend_event(self, request, *args, **kwargs):
event = self.get_object()
event.attendees.add(request.user)
return Response({'attend': True})
class CommentViewset(viewsets.ModelViewSet):
"""
An authenticated user can list, create, edit and delete a comment
"""
queryset = Comment.objects.all()
serializer_class = CommentSerializer
class ProfileViewset(viewsets.ModelViewSet):
"""
An authenticated user can retrieve, create and edit their profile
"""
queryset = Profile.objects.all()
serializer_class = ProfileSerializer
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,783
|
Gigibit/ubildin
|
refs/heads/master
|
/accounts/views.py
|
from django.urls import reverse_lazy
from django.views import generic
from .forms import SignUpForm
# Create your views here.
class SignUp(generic.CreateView):
form_class = SignUpForm
template_name = 'registration/signup.html'
success_url = reverse_lazy('login')
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,784
|
Gigibit/ubildin
|
refs/heads/master
|
/actions/urls.py
|
from django.urls import path
from . import views
app_name = 'actions'
urlpatterns = [
path('', views.NotificationList.as_view(), name='notification_list')
]
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,785
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/models.py
|
from django.db import models
from django.conf import settings
from django.shortcuts import reverse
from events.models import Event
# Create your models here.
class Comment(models.Model):
comment = models.TextField(max_length=500)
created_date = models.DateField(auto_now=True)
created_time = models.TimeField(auto_now=True)
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name='comments')
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
parent = models.ForeignKey('self', on_delete=models.CASCADE, related_name='children', null=True, blank=True)
class Meta:
ordering = ('created_date', 'created_time')
def get_absolute_url(self):
return reverse('comments:comment-detail', kwargs={'pk': self.pk})
def __str__(self):
return self.comment
def get_comment_creator_photo(self):
return self.created_by.profile.photo
def get_children(self):
return self.children.all()
def get_parents(self):
return self.parent
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,786
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/tests/test_models.py
|
from django.test import TestCase
from events.models import Category, Event, User
from userprofile.models import Profile
from comments.models import Comment
class CommentModelTest(TestCase):
@classmethod
def setUpTestData(cls):
category = Category.objects.create(name='Technology', description='This is the future')
user = User.objects.create(username='iyanu', password=12345, email='iyanu@gmail.com')
event = Event.objects.create(name='Party Out', details='This party is gonna be banging', venue='Ibadan',
date='2018-06-18', time='12:00:00', category=category, creator=user)
Comment.objects.create(comment='Hey yo', event=event, created_by=user)
Profile.objects.create(date_of_birth='2018-12-12', user=user)
def test_comment_object_name(self):
comment = Comment.objects.get(comment='Hey yo')
expected_object_name = '{}'.format(comment)
self.assertEquals(expected_object_name, str(comment))
def test_get_absolute_url(self):
comment = Comment.objects.get(comment='Hey yo')
self.assertEquals(comment.get_absolute_url(), '/events/4/')
def test_get_comment_creator_photo(self):
comment = Comment.objects.get(comment='Hey yo')
self.assertEquals(comment.get_comment_creator_photo(), None)
def test_comment_max_length(self):
comment = Comment.objects.get(comment='Hey yo')
max_length = comment._meta.get_field('comment').max_length
self.assertEquals(max_length, 500)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,787
|
Gigibit/ubildin
|
refs/heads/master
|
/events/views.py
|
from django.views import generic
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import get_object_or_404, redirect
from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.auth.models import User
from django.views import View
from django.contrib.auth.decorators import login_required
from actions.utils import create_action
from comments.models import Comment
from comments.forms import CommentForm
from .models import Event
# Create your views here.
class EventList(LoginRequiredMixin, generic.ListView):
model = Event
template_name = 'events/list_of_events.html'
context_object_name = 'events'
paginate_by = 10
def get_queryset(self):
if self.request.user.is_superuser:
return Event.objects.all()
else:
return Event.objects.all()
class EventDisplay(generic.DetailView):
model = Event
template_name = 'events/detail.html'
context_object_name = 'event'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = CommentForm()
context['comments'] = self.get_object().comments.all()
context['attending'] = self.get_object().attendees.all
return context
class CommentCreate(SuccessMessageMixin, generic.CreateView):
model = Comment
template_name = 'events/detail.html'
fields = ('comment',)
success_message = 'Comment was added successfully'
def form_valid(self, form):
form.instance = form.save(commit=False)
form.instance.event = self.get_object(queryset=Event.objects.all())
form.instance.created_by = self.request.user
create_action(self.request.user, 'added a comment', form.instance)
form.save()
return super().form_valid(form)
def get_success_url(self):
return reverse_lazy('events:event-detail', kwargs={'pk': self.get_object(Event.objects.all()).pk})
class EventDetail(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
view = EventDisplay.as_view()
return view(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
view = CommentCreate.as_view()
return view(request, *args, **kwargs)
class EventFormMixin(object):
def form_valid(self, form):
form.instance.creator = self.request.user
create_action(self.request.user, 'created a new event', form.instance)
return super().form_valid(form)
class EventCreate(LoginRequiredMixin, SuccessMessageMixin, EventFormMixin, generic.CreateView):
model = Event
template_name = 'events/create_form.html'
fields = ('category', 'name', 'details', 'venue', 'time', 'date')
context_object_name = 'event'
success_message = "%(name)s was created successfully"
class EventUpdate(LoginRequiredMixin, SuccessMessageMixin, EventFormMixin, generic.UpdateView):
model = Event
template_name = 'events/update_form.html'
template_name_suffix = '_update_form'
fields = ('category', 'name', 'details', 'venue', 'time', 'date',)
success_message = "%(name)s was updated successfully"
class EventDelete(LoginRequiredMixin, SuccessMessageMixin, generic.DeleteView):
model = Event
template_name = 'events/delete.html'
success_url = reverse_lazy('events:event-list')
context_object_name = 'event'
success_message = "%(name)s was deleted successfully"
@login_required()
def attend_event(request, event_id):
event = get_object_or_404(Event, pk=event_id)
attendee = User.objects.get(username=request.user)
event.attendees.add(attendee)
create_action(attendee, 'is attending', event)
messages.success(request, 'You are now attending {0}'.format(event.name))
return redirect('events:event-detail', pk=event.pk)
@login_required()
def not_attend_event(request, event_id):
event = get_object_or_404(Event, pk=event_id)
attendee = User.objects.get(username=request.user)
event.attendees.remove(attendee)
create_action(attendee, 'no longer attending', event)
messages.success(request, 'You are no longer attending {0}'.format(event.name))
return redirect('events:event-detail', pk=event.pk)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,788
|
Gigibit/ubildin
|
refs/heads/master
|
/lib/python3.7/site-packages/tests/test_namers.py
|
# coding: utf-8
import shutil
from mock import patch
from filebrowser.settings import VERSIONS
from tests import FilebrowserTestCase as TestCase
from filebrowser.namers import OptionsNamer
class BaseNamerTests(TestCase):
NAMER_CLASS = OptionsNamer
def setUp(self):
super(BaseNamerTests, self).setUp()
shutil.copy(self.STATIC_IMG_PATH, self.FOLDER_PATH)
def _get_namer(self, version_suffix, file_object=None, **extra_options):
if not file_object:
file_object = self.F_IMAGE
extra_options.update(VERSIONS.get(version_suffix, {}))
return self.NAMER_CLASS(
file_object=file_object,
version_suffix=version_suffix,
filename_root=file_object.filename_root,
extension=file_object.extension,
options=extra_options,
)
class OptionsNamerTests(BaseNamerTests):
def test_should_return_correct_version_name_using_predefined_versions(self):
expected = [
("admin_thumbnail", "testimage_admin-thumbnail--60x60--opts-crop.jpg", ),
("thumbnail", "testimage_thumbnail--60x60--opts-crop.jpg", ),
("small", "testimage_small--140x0.jpg", ),
("medium", "testimage_medium--300x0.jpg", ),
("big", "testimage_big--460x0.jpg", ),
("large", "testimage_large--680x0.jpg", ),
]
for version_suffix, expected_name in expected:
namer = self._get_namer(version_suffix)
self.assertEqual(namer.get_version_name(), expected_name)
@patch('filebrowser.namers.VERSION_NAMER', 'filebrowser.namers.OptionsNamer')
def test_should_return_correct_original_name_using_predefined_versions(self):
expected = 'testimage.jpg'
for version_suffix in VERSIONS.keys():
file_object = self.F_IMAGE.version_generate(version_suffix)
namer = self._get_namer(version_suffix, file_object)
self.assertNotEqual(file_object.filename, expected)
self.assertEqual(namer.get_original_name(), expected)
self.assertEqual(file_object.original_filename, expected)
def test_should_append_extra_options(self):
expected = [
(
"thumbnail",
"testimage_thumbnail--60x60--opts-crop--sepia.jpg",
{'sepia': True}
), (
"small",
"testimage_small--140x0--thumb--transparency-08.jpg",
{'transparency': 0.8, 'thumb': True}
), (
"large",
"testimage_large--680x0--nested-xpto-ops--thumb.jpg",
{'thumb': True, 'nested': {'xpto': 'ops'}}
),
]
for version_suffix, expected_name, extra_options in expected:
namer = self._get_namer(version_suffix, **extra_options)
self.assertEqual(namer.get_version_name(), expected_name)
def test_generated_version_name_options_list_should_be_ordered(self):
"the order is important to always generate the same name"
expected = [
(
"small",
"testimage_small--140x0--a--x-crop--z-4.jpg",
{'z': 4, 'a': True, 'x': 'crop'}
),
]
for version_suffix, expected_name, extra_options in expected:
namer = self._get_namer(version_suffix, **extra_options)
self.assertEqual(namer.get_version_name(), expected_name)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,789
|
Gigibit/ubildin
|
refs/heads/master
|
/accounts/forms.py
|
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from userprofile.models import Profile
from actions.utils import create_action
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=50, required=False, help_text='Optional')
last_name = forms.CharField(max_length=50, required=False, help_text='Optional')
email = forms.EmailField(max_length=254, required=True, help_text='Required. Input a valid email address')
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2',)
widgets = {
'username': forms.TextInput(attrs={'class': 'form-control'}),
'first_name': forms.TextInput(attrs={'class': 'form-control'}),
'last_name': forms.TextInput(attrs={'class': 'form-control'}),
'email': forms.TextInput(attrs={'class': 'form-control'}),
'password2': forms.TextInput(attrs={'class': 'form-control'}),
'password1': forms.TextInput(attrs={'class': 'form-control'}),
}
# This is an override of the save() method. It attaches a profile to a user when they register
def save(self, commit=True):
user = super().save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
# This is the attached profile
profile = Profile.objects.create(user=user)
# This creates an action that is displayed in the notifications page whenever an account is created
create_action(user, 'has created an account')
user.save()
return user
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,790
|
Gigibit/ubildin
|
refs/heads/master
|
/actions/tests/test_models.py
|
from django.test import TestCase
from django.contrib.auth.models import User
from actions.models import Action
class ActionModelTest(TestCase):
@classmethod
def setUpTestData(cls):
user = User.objects.create_user(username='iyanu', password=12345)
action = Action.objects.create(user = user, verb='is attending', )
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,791
|
Gigibit/ubildin
|
refs/heads/master
|
/bin/django-admin.py
|
#!/Users/luigichougrad/Downloads/meethub-master/bin/python3.7
from django.core import management
if __name__ == "__main__":
management.execute_from_command_line()
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,792
|
Gigibit/ubildin
|
refs/heads/master
|
/userprofile/tests/test_views.py
|
from django.test import TestCase
from django.contrib.auth.models import User
from django.shortcuts import reverse
from userprofile.models import Profile
class ProfileDetailViewTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.user.save()
self.profile = Profile.objects.create(user=self.user, date_of_birth='2018-05-18', photo='')
def test_user_detail(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(self.profile.get_absolute_url())
# Check the user is logged in
self.assertEqual(str(response.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('userprofile:detail', kwargs={'pk': self.profile.pk}))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('userprofile:detail', kwargs={'pk': self.profile.pk}))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'userprofile/profile_detail.html')
def test_events_created_by_this_profile(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(self.profile.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['events'])
def test_comments_created_by_this_profile(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('userprofile:detail', kwargs={'pk': self.profile.pk}))
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['comments'])
def test_date_of_birth_of_profile(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('userprofile:detail', kwargs={'pk': self.profile.pk}))
self.assertContains(response, self.profile.date_of_birth)
class EditProfileViewTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='iyanu', password=12345, email='iyanu@gmail.com')
self.profile = Profile.objects.create(user=self.user, date_of_birth='2018-05-18', photo='')
def test_edit_profile(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get('/userprofile/edit/')
# Check the user is logged in
self.assertEqual(str(response.context['user']), 'iyanu')
# Check that we got a response 'success'
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('userprofile:edit'))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('userprofile:edit'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'userprofile/update_form.html')
def test_valid_edit_profile_form_can_edit_profile(self):
self.client.login(username='iyanu', password='12345')
response = self.client.post(reverse('userprofile:edit'),
data={'user': 'self.user', 'date_of_birth': '2018-06-18', 'photo': ''})
self.assertEqual(response.status_code, 200)
new_response = self.client.get(self.profile.get_absolute_url())
self.assertEqual(new_response.status_code, 200)
self.assertEqual(Profile.objects.last().date_of_birth, '2018-06-18')
def test_edit_profile_form_is_on_edit_profile_page(self):
self.client.login(username='iyanu', password='12345')
response = self.client.get(reverse('userprofile:edit'))
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['form'])
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,793
|
Gigibit/ubildin
|
refs/heads/master
|
/comments/views.py
|
from django.urls import reverse_lazy
from django.views import generic
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from django.views import View
from django.shortcuts import get_object_or_404, render, redirect
from events.models import Event
from actions.utils import create_action
from .models import Comment
from .forms import CommentForm
# Create your views here.
class CommentDelete(LoginRequiredMixin, SuccessMessageMixin, generic.DeleteView):
model = Comment
template_name = 'comments/delete.html'
context_object_name = 'comment'
success_message = "Comment was deleted successfully"
def get_success_url(self):
return reverse_lazy('events:event-detail', kwargs={'pk': self.get_object(Event.objects.all()).pk})
@login_required()
def comment_detail(request, comment_id, event_id):
event = get_object_or_404(Event, pk=event_id)
comment = get_object_or_404(Comment, pk=comment_id)
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
new_comment = form.save(commit=False)
new_comment.event = event
new_comment.parent = comment
new_comment.created_by = request.user
create_action(request.user, 'you replied a comment', comment)
new_comment.save()
messages.success(request, 'You replied a comment')
return redirect('events:event-detail', pk=event_id)
else:
form = CommentForm()
return render(request, 'comments/detail.html', {'comment': comment, 'form': form})
class ReplyCreate(SuccessMessageMixin, generic.CreateView):
model = Comment
template_name = 'comments/detail.html'
fields = ('comment',)
success_message = 'Reply was added successfully'
def form_valid(self, form):
form.instance = form.save(commit=False)
form.instance.event = self.get_object(queryset=Event.objects.all())
form.instance.parent = self.get_object(queryset=Comment.objects.all())
form.instance.created_by = self.request.user
create_action(self.request.user, 'added a comment', form.instance)
form.save()
return super().form_valid(form)
def get_success_url(self):
return reverse_lazy('comments:comment-detail', kwargs={'pk': self.get_object(Comment.objects.all()).pk})
class CommentDisplay(generic.DetailView):
model = Comment
template_name = 'comments/detail.html'
context_object_name = 'comment'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = CommentForm()
return context
class CommentDetail(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
view = CommentDisplay.as_view()
return view(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
view = ReplyCreate.as_view()
return view(request, *args, **kwargs)
|
{"/comments/admin.py": ["/comments/models.py"], "/events/forms.py": ["/events/models.py"], "/userprofile/models.py": ["/events/models.py"], "/comments/tests/test_views.py": ["/events/models.py", "/comments/models.py"], "/userprofile/tests/test_models.py": ["/userprofile/models.py"], "/events/tests/test_models.py": ["/events/models.py"], "/comments/tests/test_forms.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py", "/comments/forms.py"], "/events/templatetags/events_tags.py": ["/events/models.py", "/comments/models.py"], "/events/tests/test_views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/userprofile/views.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/comments/forms.py": ["/comments/models.py"], "/userprofile/tests/test_forms.py": ["/userprofile/models.py"], "/events/admin.py": ["/events/models.py"], "/apiv1/serializers.py": ["/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/events/tests/test_forms.py": ["/events/forms.py", "/events/models.py"], "/apiv1/viewsets.py": ["/apiv1/serializers.py", "/events/models.py", "/comments/models.py", "/userprofile/models.py"], "/accounts/views.py": ["/accounts/forms.py"], "/comments/models.py": ["/events/models.py"], "/comments/tests/test_models.py": ["/events/models.py", "/userprofile/models.py", "/comments/models.py"], "/events/views.py": ["/comments/models.py", "/comments/forms.py", "/events/models.py"], "/accounts/forms.py": ["/userprofile/models.py"], "/userprofile/tests/test_views.py": ["/userprofile/models.py"], "/comments/views.py": ["/events/models.py", "/comments/models.py", "/comments/forms.py"]}
|
9,802
|
ReimuYk/ifstools
|
refs/heads/master
|
/ifstools/ifs.py
|
from collections import defaultdict
from multiprocessing import Pool
from os.path import basename, dirname, splitext, join, isdir, isfile, getmtime
from os import utime, walk
from io import BytesIO
import itertools
import hashlib
import lxml.etree as etree
from time import time as unixtime
from tqdm import tqdm
from kbinxml import KBinXML
from kbinxml.bytebuffer import ByteBuffer
from .handlers import GenericFolder, MD5Folder, ImageFile, ImageCanvas
from . import utils
SIGNATURE = 0x6CAD8F89
FILE_VERSION = 3
# must be toplevel or can't be pickled
def _extract(args):
f, path, kwargs = args
f.extract(path, **kwargs)
return f
def _load(args):
f, kwargs = args
f.preload(**kwargs)
return f.full_path
class FileBlob(object):
''' a basic wrapper around a file to deal with IFS data offset '''
def __init__(self, file, offset):
self.file = file
self.offset = offset
def get(self, offset, size):
self.file.seek(offset + self.offset)
return self.file.read(size)
class IFS:
def __init__(self, path, super_disable = False, super_skip_bad = False,
super_abort_if_bad = False):
if isfile(path):
self.load_ifs(path, super_disable, super_skip_bad, super_abort_if_bad)
elif isdir(path):
self.load_dir(path)
else:
raise IOError('Input path {} does not exist'.format(path))
def load_ifs(self, path, super_disable = False, super_skip_bad = False,
super_abort_if_bad = False):
self.is_file = True
name = basename(path)
self.ifs_out = name
self.folder_out = splitext(name)[0] + '_ifs'
self.default_out = self.folder_out
self.file = open(path, 'rb')
header = ByteBuffer(self.file.read(36))
signature = header.get_u32()
if signature != SIGNATURE:
raise IOError('Given file was not an IFS file!')
self.file_version = header.get_u16()
# next u16 is just NOT(version)
assert header.get_u16() ^ self.file_version == 0xFFFF
self.time = header.get_u32()
ifs_tree_size = header.get_u32()
manifest_end = header.get_u32()
self.data_blob = FileBlob(self.file, manifest_end)
self.manifest_md5 = None
if self.file_version > 1:
self.manifest_md5 = header.get_bytes(16)
self.file.seek(header.offset)
self.manifest = KBinXML(self.file.read(manifest_end-header.offset))
self.tree = GenericFolder(self.data_blob, self.manifest.xml_doc,
super_disable=super_disable, super_skip_bad=super_skip_bad,
super_abort_if_bad=super_abort_if_bad
)
# IFS files repacked with other tools usually have wrong values - don't validate this
#assert ifs_tree_size == self.manifest.mem_size
def load_dir(self, path):
self.is_file = False
self.file = None
path = path.rstrip('/\\')
self.folder_out = basename(path)
if '_ifs' in self.folder_out:
self.ifs_out = self.folder_out.replace('_ifs', '.ifs')
else:
self.ifs_out = self.folder_out + '.ifs'
self.default_out = self.ifs_out
self.file_version = FILE_VERSION
self.time = int(getmtime(path))
self.data_blob = None
self.manifest = None
os_tree = self._create_dir_tree(path)
self.tree = GenericFolder(None, os_tree)
def _create_dir_tree(self, path):
tree = self._create_dir_tree_recurse(walk(path))
if 'ifs_manifest.xml' in tree['files']:
tree['files'].remove('ifs_manifest.xml')
return tree
def _create_dir_tree_recurse(self, walker):
tree = {}
root, dirs, files = next(walker)
tree['path'] = root
tree['files'] = files
tree['folders'] = []
for dir in dirs:
tree['folders'].append(self._create_dir_tree_recurse(walker))
return tree
def close(self):
if self.file:
self.file.close()
def __str__(self):
return str(self.tree)
def extract(self, progress = True, recurse = True, tex_only = False,
extract_manifest = False, path = None, rename_dupes = False, **kwargs):
if path is None:
path = self.folder_out
if tex_only:
kwargs['use_cache'] = False
utils.mkdir_silent(path)
utime(path, (self.time, self.time))
if extract_manifest and self.manifest and not tex_only:
with open(join(path, 'ifs_manifest.xml'), 'wb') as f:
f.write(self.manifest.to_text().encode('utf8'))
# build the tree
for folder in self.tree.all_folders:
if tex_only and folder.name == 'tex':
self.tree = folder
# make it root to discourage repacking
folder.name = ''
for f in folder.all_files:
f.path = ''
break
elif tex_only:
continue
f_path = join(path, folder.full_path)
utils.mkdir_silent(f_path)
utime(f_path, (self.time, self.time))
# handle different-case-but-same-name for Windows
same_name = defaultdict(list)
for name, obj in folder.files.items():
same_name[name.lower()].append(obj)
for files in same_name.values():
# common base case of "sane ifs file"
if len(files) == 1:
continue
# make them 'a (1)', 'a (2)' etc
if rename_dupes:
for i, f in enumerate(files[1:]):
base, ext = splitext(f.name)
f.name = base + ' ({})'.format(i+1) + ext
elif progress: # warn if not silenced
all_names = ', '.join([f.name for f in files])
tqdm.write('WARNING: Files with same name and differing case will overwrite on Windows ({}). '.format(all_names) +
'Use --rename-dupes to extract without loss')
# else just do nothing
# extract the files
for f in tqdm(self.tree.all_files, disable = not progress):
# allow recurse + tex_only to extract ifs files
if tex_only and not isinstance(f, ImageFile) and not isinstance(f, ImageCanvas) and not (recurse and f.name.endswith('.ifs')):
continue
f.extract(path, **kwargs)
if progress:
tqdm.write(f.full_path)
if recurse and f.name.endswith('.ifs'):
rpath = join(path, f.full_path)
i = IFS(rpath)
i.extract(progress=progress, recurse=recurse, tex_only=tex_only,
extract_manifest=extract_manifest, path=rpath.replace('.ifs','_ifs'),
rename_dupes=rename_dupes, **kwargs)
# you can't pickle open files, so this won't work. Perhaps there is a way around it?
'''to_extract = (f for f in self.tree.all_files if not(tex_only and not isinstance(f, ImageFile) and not isinstance(f, ImageCanvas)))
p = Pool()
args = zip(to_extract, itertools.cycle((path,)), itertools.cycle((kwargs,)))
to_recurse = []
for f in tqdm(p.imap_unordered(_extract, args)):
if progress:
tqdm.write(f)
if recurse and f.name.endswith('.ifs'):
to_recurse.append(join(path, f.full_path))
for rpath in recurse:
i = IFS(rpath)
i.extract(progress=progress, recurse=recurse, tex_only=tex_only,
extract_manifest=extract_manifest, path=rpath.replace('.ifs','_ifs'), **kwargs)'''
def repack(self, progress = True, path = None, **kwargs):
if path is None:
path = self.ifs_out
# open first in case path is bad
ifs_file = open(path, 'wb')
self.data_blob = BytesIO()
self.manifest = KBinXML(etree.Element('imgfs'))
manifest_info = etree.SubElement(self.manifest.xml_doc, '_info_')
# the important bit
data = self._repack_tree(progress, **kwargs)
data_md5 = etree.SubElement(manifest_info, 'md5')
data_md5.attrib['__type'] = 'bin'
data_md5.attrib['__size'] = '16'
data_md5.text = hashlib.md5(data).hexdigest()
data_size = etree.SubElement(manifest_info, 'size')
data_size.attrib['__type'] = 'u32'
data_size.text = str(len(data))
manifest_bin = self.manifest.to_binary()
manifest_hash = hashlib.md5(manifest_bin).digest()
head = ByteBuffer()
head.append_u32(SIGNATURE)
head.append_u16(self.file_version)
head.append_u16(self.file_version ^ 0xFFFF)
head.append_u32(int(unixtime()))
head.append_u32(self.manifest.mem_size)
manifest_end = len(manifest_bin) + head.offset + 4
if self.file_version > 1:
manifest_end += 16
head.append_u32(manifest_end)
if self.file_version > 1:
head.append_bytes(manifest_hash)
ifs_file.write(head.data)
ifs_file.write(manifest_bin)
ifs_file.write(data)
ifs_file.close()
def _repack_tree(self, progress = True, **kwargs):
folders = self.tree.all_folders
files = self.tree.all_files
# Can't pickle lmxl, so to dirty-hack land we go
kbin_backup = []
for folder in folders:
if isinstance(folder, MD5Folder):
kbin_backup.append(folder.info_kbin)
folder.info_kbin = None
needs_preload = (f for f in files if f.needs_preload or not kwargs['use_cache'])
args = list(zip(needs_preload, itertools.cycle((kwargs,))))
p = Pool()
for f in tqdm(p.imap_unordered(_load, args), desc='Caching', total=len(args), disable = not progress):
if progress:
tqdm.write(f)
p.close()
p.terminate()
# restore stuff from before
for folder in folders:
if isinstance(folder, MD5Folder):
folder.info_kbin = kbin_backup.pop(0)
tqdm_progress = None
if progress:
tqdm_progress = tqdm(desc='Writing', total=len(files))
self.tree.repack(self.manifest.xml_doc, self.data_blob, tqdm_progress, **kwargs)
return self.data_blob.getvalue()
|
{"/ifstools/ifs.py": ["/ifstools/handlers/__init__.py", "/ifstools/__init__.py"], "/ifstools/handlers/TexFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py"], "/ifstools/handlers/MD5Folder.py": ["/ifstools/handlers/__init__.py"], "/ifstools_bin.py": ["/ifstools/__init__.py"], "/ifstools/handlers/AfpFolder.py": ["/ifstools/handlers/__init__.py"], "/ifstools/handlers/GenericFile.py": ["/ifstools/handlers/Node.py", "/ifstools/__init__.py"], "/ifstools/handlers/ImageFile.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py", "/ifstools/__init__.py"], "/ifstools/__init__.py": ["/ifstools/ifstools.py", "/ifstools/ifs.py", "/ifstools/handlers/__init__.py"], "/ifstools/handlers/__init__.py": ["/ifstools/handlers/Node.py", "/ifstools/handlers/GenericFile.py", "/ifstools/handlers/ImageFile.py", "/ifstools/handlers/GenericFolder.py", "/ifstools/handlers/MD5Folder.py", "/ifstools/handlers/AfpFolder.py", "/ifstools/handlers/TexFolder.py"], "/ifstools/handlers/GenericFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/Node.py", "/ifstools/ifs.py"], "/ifstools/ifstools.py": ["/ifstools/ifs.py"]}
|
9,803
|
ReimuYk/ifstools
|
refs/heads/master
|
/ifstools/handlers/TexFolder.py
|
from io import BytesIO
from kbinxml import KBinXML
from tqdm import tqdm
from PIL import Image, ImageDraw
from . import MD5Folder, ImageFile, GenericFile
from .ImageDecoders import cachable_formats
class TextureList(GenericFile):
def _load_from_filesystem(self, **kwargs):
raw = GenericFile._load_from_filesystem(self, **kwargs)
k = KBinXML(raw)
# fallback to a type we can encode
for tex in k.xml_doc.iterchildren():
if tex.attrib['format'] not in cachable_formats:
tex.attrib['format'] = 'argb8888rev'
return k.to_binary()
class ImageCanvas(GenericFile):
def __init__(self, name, size, images, parent):
self.name = '_canvas_{}.png'.format(name)
self._packed_name = self.name
self.time = parent.time
self.path = parent.path
self.images = images
self.img_size = size
def extract(self, base, dump_canvas = False, **kwargs):
if dump_canvas:
GenericFile.extract(self, base, **kwargs)
def load(self, draw_bbox = False, **kwargs):
''' Makes the canvas.
This could be far speedier if it copied raw pixels, but that would
take far too much time to write vs using Image inbuilts '''
im = Image.new('RGBA', self.img_size)
draw = None
if draw_bbox:
draw = ImageDraw.Draw(im)
for sprite in self.images:
data = sprite.load()
sprite_im = Image.open(BytesIO(data))
size = sprite.imgrect
im.paste(sprite_im, (size[0], size[2]))
if draw_bbox:
draw.rectangle((size[0], size[2], size[1], size[3]), outline='red')
del draw
b = BytesIO()
im.save(b, format = 'PNG')
return b.getvalue()
# since it's basically metadata, we ignore similarly to _cache
def repack(self, manifest, data_blob, tqdm_progress, **kwargs):
return
class TexFolder(MD5Folder):
def __init__(self, ifs_data, obj, parent = None, path = '', name = '', supers = None,
super_disable = False, super_skip_bad = False, super_abort_if_bad = False):
MD5Folder.__init__(self, ifs_data, obj, parent, path, name, supers,
super_disable, super_skip_bad, super_abort_if_bad, 'image', '.png')
def tree_complete(self):
MD5Folder.tree_complete(self)
if '_cache' in self.folders:
self.folders.pop('_cache')
if not self.info_kbin:
return
self.compress = self.info_kbin.xml_doc.attrib.get('compress')
self.info_file.__class__ = TextureList
self._create_images()
def _create_images(self):
for tex in self.info_kbin.xml_doc.iterchildren():
folder = tex.attrib['name']
fmt = tex.attrib['format']
canvas_contents = []
canvas_size = None
for indiv in tex.iterchildren():
if indiv.tag == 'size':
canvas_size = self._split_ints(indiv.text)
elif indiv.tag == 'image':
name = indiv.attrib['name'] + '.png'
if name in self.files:
ImageFile.upgrade_generic(self.files[name], indiv, fmt, self.compress)
canvas_contents.append(self.files[name])
else:
tqdm.write('Unknown texturelist.xml element {}'.format(indiv.tag))
canvas = ImageCanvas(folder, canvas_size, canvas_contents, self)
self.files[canvas.name] = canvas
|
{"/ifstools/ifs.py": ["/ifstools/handlers/__init__.py", "/ifstools/__init__.py"], "/ifstools/handlers/TexFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py"], "/ifstools/handlers/MD5Folder.py": ["/ifstools/handlers/__init__.py"], "/ifstools_bin.py": ["/ifstools/__init__.py"], "/ifstools/handlers/AfpFolder.py": ["/ifstools/handlers/__init__.py"], "/ifstools/handlers/GenericFile.py": ["/ifstools/handlers/Node.py", "/ifstools/__init__.py"], "/ifstools/handlers/ImageFile.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py", "/ifstools/__init__.py"], "/ifstools/__init__.py": ["/ifstools/ifstools.py", "/ifstools/ifs.py", "/ifstools/handlers/__init__.py"], "/ifstools/handlers/__init__.py": ["/ifstools/handlers/Node.py", "/ifstools/handlers/GenericFile.py", "/ifstools/handlers/ImageFile.py", "/ifstools/handlers/GenericFolder.py", "/ifstools/handlers/MD5Folder.py", "/ifstools/handlers/AfpFolder.py", "/ifstools/handlers/TexFolder.py"], "/ifstools/handlers/GenericFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/Node.py", "/ifstools/ifs.py"], "/ifstools/ifstools.py": ["/ifstools/ifs.py"]}
|
9,804
|
ReimuYk/ifstools
|
refs/heads/master
|
/ifstools/utils.py
|
import errno
import os
def mkdir_silent(dir):
try: # python 3
FileExistsError
try:
os.mkdir(dir)
except FileExistsError:
pass
except NameError: # python 2
try:
os.mkdir(dir)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
def save_with_timestamp(filename, data, timestamp):
mkdir_silent(os.path.dirname(filename))
with open(filename, 'wb') as f:
f.write(data)
# we store invalid timestamps as -1
if timestamp >= 0:
os.utime(filename, (timestamp,timestamp))
|
{"/ifstools/ifs.py": ["/ifstools/handlers/__init__.py", "/ifstools/__init__.py"], "/ifstools/handlers/TexFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py"], "/ifstools/handlers/MD5Folder.py": ["/ifstools/handlers/__init__.py"], "/ifstools_bin.py": ["/ifstools/__init__.py"], "/ifstools/handlers/AfpFolder.py": ["/ifstools/handlers/__init__.py"], "/ifstools/handlers/GenericFile.py": ["/ifstools/handlers/Node.py", "/ifstools/__init__.py"], "/ifstools/handlers/ImageFile.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py", "/ifstools/__init__.py"], "/ifstools/__init__.py": ["/ifstools/ifstools.py", "/ifstools/ifs.py", "/ifstools/handlers/__init__.py"], "/ifstools/handlers/__init__.py": ["/ifstools/handlers/Node.py", "/ifstools/handlers/GenericFile.py", "/ifstools/handlers/ImageFile.py", "/ifstools/handlers/GenericFolder.py", "/ifstools/handlers/MD5Folder.py", "/ifstools/handlers/AfpFolder.py", "/ifstools/handlers/TexFolder.py"], "/ifstools/handlers/GenericFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/Node.py", "/ifstools/ifs.py"], "/ifstools/ifstools.py": ["/ifstools/ifs.py"]}
|
9,805
|
ReimuYk/ifstools
|
refs/heads/master
|
/ifstools/handlers/lz77.py
|
# consistency with py 2/3
from builtins import bytes
from struct import unpack, pack
from io import BytesIO
from tqdm import tqdm
WINDOW_SIZE = 0x1000
WINDOW_MASK = WINDOW_SIZE - 1
THRESHOLD = 3
INPLACE_THRESHOLD = 0xA
LOOK_RANGE = 0x200
MAX_LEN = 0xF + THRESHOLD
def decompress(input):
input = BytesIO(input)
decompressed = bytearray()
while True:
# wrap in bytes for py2
flag = bytes(input.read(1))[0]
for i in range(8):
if (flag >> i) & 1 == 1:
decompressed.append(input.read(1)[0])
else:
w = unpack('>H', input.read(2))[0]
position = (w >> 4)
length = (w & 0x0F) + THRESHOLD
if position == 0:
return bytes(decompressed)
if position > len(decompressed):
diff = position - len(decompressed)
diff = min(diff, length)
decompressed.extend([0]*diff)
length -= diff
# optimise
if -position+length < 0:
decompressed.extend(decompressed[-position:-position+length])
else:
for loop in range(length):
decompressed.append(decompressed[-position])
def match_window(in_data, offset):
'''Find the longest match for the string starting at offset in the preceeding data
'''
window_start = max(offset - WINDOW_MASK, 0)
for n in range(MAX_LEN, THRESHOLD-1, -1):
window_end = min(offset + n, len(in_data))
# we've not got enough data left for a meaningful result
if window_end - offset < THRESHOLD:
return None
str_to_find = in_data[offset:window_end]
idx = in_data.rfind(str_to_find, window_start, window_end-n)
if idx != -1:
code_offset = offset - idx # - 1
code_len = len(str_to_find)
return (code_offset, code_len)
return None
def compress(input, progress = False):
pbar = tqdm(total = len(input), leave = False, unit = 'b', unit_scale = True,
desc = 'Compressing', disable = not progress)
compressed = bytearray()
input = bytes([0]*WINDOW_SIZE) + bytes(input)
input_size = len(input)
current_pos = WINDOW_SIZE
bit = 0
while current_pos < input_size:
flag_byte = 0;
buf = bytearray()
for _ in range(8):
if current_pos >= input_size:
bit = 0;
else:
match = match_window(input, current_pos)
if match:
pos, length = match
info = (pos << 4) | ((length - THRESHOLD) & 0x0F)
buf.extend(pack('>H', info))
bit = 0
current_pos += length
pbar.update(length)
else:
buf.append(input[current_pos])
current_pos += 1
pbar.update(1)
bit = 1
flag_byte = (flag_byte >> 1) | ((bit & 1) << 7)
compressed.append(flag_byte)
compressed.extend(buf)
compressed.append(0)
compressed.append(0)
compressed.append(0)
pbar.close()
return bytes(compressed)
def compress_dummy(input):
input_length = len(input)
compressed = bytearray()
extra_bytes = input_length % 8
for i in range(0, input_length-extra_bytes, 8):
compressed.append(0xFF)
compressed.extend(input[i:i+8])
if extra_bytes > 0:
compressed.append(0xFF >> (8 - extra_bytes))
compressed.extend(input[-extra_bytes:])
compressed.append(0)
compressed.append(0)
compressed.append(0)
return bytes(compressed)
|
{"/ifstools/ifs.py": ["/ifstools/handlers/__init__.py", "/ifstools/__init__.py"], "/ifstools/handlers/TexFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py"], "/ifstools/handlers/MD5Folder.py": ["/ifstools/handlers/__init__.py"], "/ifstools_bin.py": ["/ifstools/__init__.py"], "/ifstools/handlers/AfpFolder.py": ["/ifstools/handlers/__init__.py"], "/ifstools/handlers/GenericFile.py": ["/ifstools/handlers/Node.py", "/ifstools/__init__.py"], "/ifstools/handlers/ImageFile.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py", "/ifstools/__init__.py"], "/ifstools/__init__.py": ["/ifstools/ifstools.py", "/ifstools/ifs.py", "/ifstools/handlers/__init__.py"], "/ifstools/handlers/__init__.py": ["/ifstools/handlers/Node.py", "/ifstools/handlers/GenericFile.py", "/ifstools/handlers/ImageFile.py", "/ifstools/handlers/GenericFolder.py", "/ifstools/handlers/MD5Folder.py", "/ifstools/handlers/AfpFolder.py", "/ifstools/handlers/TexFolder.py"], "/ifstools/handlers/GenericFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/Node.py", "/ifstools/ifs.py"], "/ifstools/ifstools.py": ["/ifstools/ifs.py"]}
|
9,806
|
ReimuYk/ifstools
|
refs/heads/master
|
/ifstools/handlers/ImageDecoders.py
|
from io import BytesIO
from struct import unpack, pack
from PIL import Image
from tqdm import tqdm
# header for a standard DDS with DXT5 compression and RGBA pixels
# gap placed for image height/width insertion
dxt_start = b'DDS |\x00\x00\x00\x07\x10\x00\x00'
dxt_middle = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x04' + \
b'\x00\x00\x00'
dxt_end = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00' + \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
def check_size(ifs_img, data, bytes_per_pixel):
need = ifs_img.img_size[0] * ifs_img.img_size[1] * bytes_per_pixel
if len(data) < need:
tqdm.write('WARNING: Not enough image data for {}, padding'.format(ifs_img.name))
data += b'\x00' * (need-len(data))
return data
def decode_argb8888rev(ifs_img, data):
data = check_size(ifs_img, data, 4)
return Image.frombytes('RGBA', ifs_img.img_size, data, 'raw', 'BGRA')
def encode_argb8888rev(ifs_img, image):
return image.tobytes('raw', 'BGRA')
def decode_argb4444(ifs_img, data):
data = check_size(ifs_img, data, 2)
im = Image.frombytes('RGBA', ifs_img.img_size, data, 'raw', 'RGBA;4B')
# there's no BGRA;4B
r, g, b, a = im.split()
return Image.merge('RGBA', (b, g, r, a))
def decode_dxt(ifs_img, data, version):
b = BytesIO()
b.write(dxt_start)
b.write(pack('<2I', ifs_img.img_size[1], ifs_img.img_size[0]))
b.write(dxt_middle)
b.write(version)
b.write(dxt_end)
# the data has swapped endianness for every WORD
l = len(data)//2
big = unpack('>{}H'.format(l), data)
little = pack('<{}H'.format(l), *big)
b.write(little)
return Image.open(b)
def decode_dxt5(ifs_img, data):
return decode_dxt(ifs_img, data, b'DXT5')
def decode_dxt1(ifs_img, data):
return decode_dxt(ifs_img, data, b'DXT1')
image_formats = {
'argb8888rev' : {'decoder': decode_argb8888rev, 'encoder': encode_argb8888rev},
'argb4444' : {'decoder': decode_argb4444, 'encoder': None},
'dxt1' : {'decoder': decode_dxt1, 'encoder': None},
'dxt5' : {'decoder': decode_dxt5, 'encoder': None},
}
cachable_formats = [key for key, val in image_formats.items() if val['encoder'] is not None]
|
{"/ifstools/ifs.py": ["/ifstools/handlers/__init__.py", "/ifstools/__init__.py"], "/ifstools/handlers/TexFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py"], "/ifstools/handlers/MD5Folder.py": ["/ifstools/handlers/__init__.py"], "/ifstools_bin.py": ["/ifstools/__init__.py"], "/ifstools/handlers/AfpFolder.py": ["/ifstools/handlers/__init__.py"], "/ifstools/handlers/GenericFile.py": ["/ifstools/handlers/Node.py", "/ifstools/__init__.py"], "/ifstools/handlers/ImageFile.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py", "/ifstools/__init__.py"], "/ifstools/__init__.py": ["/ifstools/ifstools.py", "/ifstools/ifs.py", "/ifstools/handlers/__init__.py"], "/ifstools/handlers/__init__.py": ["/ifstools/handlers/Node.py", "/ifstools/handlers/GenericFile.py", "/ifstools/handlers/ImageFile.py", "/ifstools/handlers/GenericFolder.py", "/ifstools/handlers/MD5Folder.py", "/ifstools/handlers/AfpFolder.py", "/ifstools/handlers/TexFolder.py"], "/ifstools/handlers/GenericFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/Node.py", "/ifstools/ifs.py"], "/ifstools/ifstools.py": ["/ifstools/ifs.py"]}
|
9,807
|
ReimuYk/ifstools
|
refs/heads/master
|
/ifstools/handlers/MD5Folder.py
|
from hashlib import md5
from kbinxml import KBinXML
from . import GenericFolder
class MD5Folder(GenericFolder):
def __init__(self, ifs_data, parent, obj, path = '', name = '', supers = None,
super_disable = False, super_skip_bad = False,
super_abort_if_bad = False, md5_tag = None, extension = None):
GenericFolder.__init__(self, ifs_data, parent, obj, path, name, supers,
super_disable, super_skip_bad, super_abort_if_bad)
self.md5_tag = md5_tag if md5_tag else self.name
self.extension = extension
def tree_complete(self):
GenericFolder.tree_complete(self)
self.info_kbin = None
self.info_file = None
for filename, file in self.files.items():
if filename.endswith('.xml'):
self.info_file = file
break
if not self.info_file:
#raise KeyError('MD5 folder contents have no mapping xml')
# _super_ references to info XML breaks things - just extract what we can
return
self.info_kbin = KBinXML(self.info_file.load(convert_kbin = False))
self._apply_md5()
def _apply_md5(self):
# findall needs xpath or it'll only search direct children
names = (tag.attrib['name'] for tag in self.info_kbin.xml_doc.findall('.//' + self.md5_tag))
self._apply_md5_folder(names, self)
def _apply_md5_folder(self, plain_list, folder):
for plain in plain_list:
hashed = md5(plain.encode(self.info_kbin.encoding)).hexdigest()
if self.extension:
plain += self.extension
# add correct packed name to deobfuscated filesystems
if plain in folder.files:
folder.files[plain]._packed_name = hashed
# deobfuscate packed filesystems
if hashed in folder.files:
orig = folder.files.pop(hashed)
orig.name = plain
folder.files[plain] = orig
|
{"/ifstools/ifs.py": ["/ifstools/handlers/__init__.py", "/ifstools/__init__.py"], "/ifstools/handlers/TexFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py"], "/ifstools/handlers/MD5Folder.py": ["/ifstools/handlers/__init__.py"], "/ifstools_bin.py": ["/ifstools/__init__.py"], "/ifstools/handlers/AfpFolder.py": ["/ifstools/handlers/__init__.py"], "/ifstools/handlers/GenericFile.py": ["/ifstools/handlers/Node.py", "/ifstools/__init__.py"], "/ifstools/handlers/ImageFile.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/ImageDecoders.py", "/ifstools/__init__.py"], "/ifstools/__init__.py": ["/ifstools/ifstools.py", "/ifstools/ifs.py", "/ifstools/handlers/__init__.py"], "/ifstools/handlers/__init__.py": ["/ifstools/handlers/Node.py", "/ifstools/handlers/GenericFile.py", "/ifstools/handlers/ImageFile.py", "/ifstools/handlers/GenericFolder.py", "/ifstools/handlers/MD5Folder.py", "/ifstools/handlers/AfpFolder.py", "/ifstools/handlers/TexFolder.py"], "/ifstools/handlers/GenericFolder.py": ["/ifstools/handlers/__init__.py", "/ifstools/handlers/Node.py", "/ifstools/ifs.py"], "/ifstools/ifstools.py": ["/ifstools/ifs.py"]}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.