Python Developer Assessment Guide
Python Developer Assessment Guide
A recursive function to list prime numbers up to 30 involves checking each number for primality using a helper function that tests divisibility recursively. Start by defining a function `is_prime` that checks divisibility from 2 up to the square root of the number. Then, create a driver function that initializes a list and incrementally tests numbers, invoking `is_prime`, and collecting those that are prime until 30, employing recursive calls to continue checking each number.
Python manages memory using reference counting and garbage collection. For example, `Var1 = [1, 2, 3]` creates a list object referenced by Var1. When `Var2 = Var1` is executed, Var2 references the same list; no new copy is made. When `Var1.append(4)` is called, the list object is modified directly. However, reassigning `Var2 = (1, 2)` makes Var2 reference a new tuple object. Attempting `Var2[0] = 3` would raise an error, as tuples are immutable. Each step involves creating new objects or modifying existing ones, which Python handles efficiently.
When optimizing a SQL query that involves nested subqueries filtering employees based on the city, consider transforming the query to join operations which often perform better than nested subqueries. For instance, use INNER JOINS to connect the emp, department, and cities tables and filter directly on the city column, reducing unnecessary subquery computations. Also, ensure that appropriate indexes exist on the columns used in the JOINs and WHERE filters to enhance query performance.
To implement a custom Python logic that finds the index of a substring occurrence, you can iterate through the main string and compare segments of it to the substring manually. For each starting point in the main string, extract a segment of the same length as the substring and then compare it character by character to the substring. If a match is found, return the current starting index. This avoids the use of built-in functions like `str.find()` or `str.index()`.
To implement a scalable data structure for traversing a tree diagram, use classes to represent nodes and the tree itself. Create a `Node` class with properties for storing data and child nodes, and a `Tree` class with methods for adding nodes, performing traversal (like BFS or DFS for easy searching). Implement methods that can dynamically extend the tree structure, maintaining references to children nodes, ensuring optimal performance even as it scales to Nth levels.
To compute and display the total number of employees and highest salary per department, first read the CSV file using Python's `csv.reader` to parse data row-by-row. Use a dictionary to keep track of each department's employee count and the highest salary encountered. As you iterate through each row, update the dictionary by incrementing the employee count and comparing salaries to update the highest salary if necessary. Finally, format the output for each department showing the total employees and highest salary.