Khauneesh Saigal commited on
Commit ·
393acb0
1
Parent(s): 19ac869
Add QA pairs results
Browse files
qa_pairs_claude_20241203_220457_test.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"results": {
|
| 3 |
+
"python_basics": [
|
| 4 |
+
{
|
| 5 |
+
"question": "How do you create and use a list in Python?",
|
| 6 |
+
"solution": "Here's how to work with lists in Python:\n\n```python\n# Creating a list\nmy_list = [1, 2, 3, 4, 5]\n\n# Adding elements\nmy_list.append(6) # Adds to end of list\nmy_list.insert(0, 0) # Inserts at specific index\n\n# Accessing elements\nfirst_item = my_list[0] # Get first item\nlast_item = my_list[-1] # Get last item\n\n# Slicing\nsub_list = my_list[1:4] # Gets elements from index 1 to 3\n\nprint(my_list) # Output: [0, 1, 2, 3, 4, 5, 6]\nprint(sub_list) # Output: [1, 2, 3]\n```"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"question": "How do you use a for loop in Python?",
|
| 10 |
+
"solution": "Here's how to use for loops in Python:\n\n```python\n# Loop through a range of numbers\nfor i in range(5):\n print(i) # Prints 0, 1, 2, 3, 4\n\n# Loop through a list\nfruits = ['apple', 'banana', 'orange']\nfor fruit in fruits:\n print(f'I like {fruit}s')\n\n# Loop with enumerate to get both index and value\nfor index, fruit in enumerate(fruits):\n print(f'Fruit {index + 1}: {fruit}')\n\n# Loop through a dictionary\nuser = {'name': 'John', 'age': 30}\nfor key, value in user.items():\n print(f'{key}: {value}')\n```\n\nThe for loop in Python is very versatile and can iterate over any sequence (lists, tuples, strings) or other iterable objects."
|
| 11 |
+
}
|
| 12 |
+
],
|
| 13 |
+
"data_structures": [
|
| 14 |
+
{
|
| 15 |
+
"question": "How do you create and use a Stack data structure in Python?",
|
| 16 |
+
"solution": "A Stack can be implemented using a Python list with push and pop operations. Here's an example:\n\n```python\nclass Stack:\n def __init__(self):\n self.items = [] # Initialize empty list\n \n def push(self, item):\n self.items.append(item) # Add item to top\n \n def pop(self):\n if not self.is_empty():\n return self.items.pop() # Remove and return top item\n \n def is_empty(self):\n return len(self.items) == 0\n\n# Example usage\nstack = Stack()\nstack.push(1)\nstack.push(2)\nstack.push(3)\nprint(stack.pop()) # Output: 3\nprint(stack.pop()) # Output: 2\n```"
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"question": "How do you implement a simple Binary Tree in Python?",
|
| 20 |
+
"solution": "Here's how to implement a basic Binary Tree with a Node class and tree traversal:\n\n```python\nclass Node:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\nclass BinaryTree:\n def __init__(self):\n self.root = None\n \n def inorder_traversal(self, node):\n if node:\n # Traverse left subtree\n self.inorder_traversal(node.left)\n # Print current node\n print(node.value, end=' ')\n # Traverse right subtree\n self.inorder_traversal(node.right)\n\n# Example usage\ntree = BinaryTree()\ntree.root = Node(1)\ntree.root.left = Node(2)\ntree.root.right = Node(3)\n\nprint('Inorder traversal:')\ntree.inorder_traversal(tree.root) # Output: 2 1 3\n```"
|
| 21 |
+
}
|
| 22 |
+
]
|
| 23 |
+
},
|
| 24 |
+
"errors": null
|
| 25 |
+
}
|