Python Code Support Documentation
This document explains the current platform's support scope and limitations for the Python language.
Please adhere to the following rules to avoid using incompatible syntax features.
Common issues
Common issues
Supported Features
1. Basic Data Types
The following basic types are supported for declaration and use:
str, int, float, bool
Example:
num = 42;
name = "Alice";
pi = 3.1415;
Generating interactive preview...
2. Containers
The following containers are supported:
| Container Type | Example |
|---|
| One-dimensional array | arr=[1,2,3] |
| Two-dimensional array | arr=[[1,2,3],[4,5,6]] |
| dict | dict={"name":"Alice","age":18} |
| Queue | q = Queue();q.enqueue(1);q.dequeue() |
| Stack | s = Stack();s.push(1);s.pop() |
Constraints:
- Keys and values in dict must be of basic types
3. Built-in Data Structures
The following predefined structures can be used directly:
# ListNode(val: Union[int, str, None] = 0, next: Optional["ListNode"] = None)
l1 = ListNode(1);
l1.next = ListNode(2);
# TreeNode(val: int, left: Optional["TreeNode"] = None, right: Optional["TreeNode"] = None)
l1 = TreeNode(1);
l1.left = TreeNode(2);
l1.right = TreeNode(3);
Generating interactive preview...
4. Notes
- Do not wrap your executable code in
if __name__ == "__main__":. When we execute your code in the sandbox, it is not in the main file, so this if condition will return False. You can directly write the code you need to execute.
class Solution(object):
def spiralOrder(self, matrix):
if not matrix or not matrix[0]:
return []
# Extract the first row
first_row = matrix[0]
# Recursively process the remaining part: remove the first row and rotate 90 degrees counterclockwise
remaining = [row for row in matrix[1:]]
if remaining and remaining[0]:
# Convert the rotated tuples into lists
rotated = [list(row) for row in list(zip(*remaining))[::-1]]
ans = first_row + self.spiralOrder(rotated)
return ans
else:
return first_row
# Execute your code directly
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
solution = Solution()
result = solution.spiralOrder(matrix)
class Solution(object):
def spiralOrder(self, matrix):
if not matrix or not matrix[0]:
return []
# Extract the first row
first_row = matrix[0]
# Recursively process the remaining part: remove the first row and rotate 90 degrees counterclockwise
remaining = [row for row in matrix[1:]]
if remaining and remaining[0]:
# Convert the rotated tuples into lists
rotated = [list(row) for row in list(zip(*remaining))[::-1]]
ans = first_row + self.spiralOrder(rotated)
return ans
else:
return first_row
# The if condition returns False, and the entire code has only one step
if __name__ == "__main__":
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
solution = Solution()
result = solution.spiralOrder(matrix)
print(result)
Generating interactive preview...