LastRecitationProxy

pdf

School

Rutgers University *

*We aren’t endorsed by this school

Course

198:336

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

15

Uploaded by MinisterWallaby3964

Report
Strings and Loops: Write a Python function duplicate_chars that takes a string as input and returns a new string where each character in the original string is repeated twice. For example, duplicate_chars('abc') should return 'aabbcc'.
List Comprehension: Given a list of numbers, write a single line of Python code using list comprehension to create a new list which contains only the odd numbers from the original list multiplied by 2.
Tuples and Functions: Write a Python function max_min_avg that takes a list of tuples, where each tuple contains three numbers. The function should return a tuple containing the maximum, minimum, and average of all the numbers in the input list of tuples. For example, max_min_avg([(1, 2, 3), (4, 5, 6)]) should return (6, 1, 3.5).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Dictionaries and Loops: Write a Python function invert_dict that takes a dictionary as input and returns a new dictionary where the keys are the values of the original dictionary and the values are lists of keys from the original dictionary that had the corresponding value. Assume all values are hashable.
Inline Function Lambda and List Comprehension: Write a single line of Python code that uses lambda function and list comprehension to create a list of squares of all even numbers from 0 to 20 (inclusive).
Loops and String Manipulation: Write a Python function string_alternate that takes a string as input and returns a new string consisting of every alternate character from the original string, starting with the first character. For example, string_alternate('abcdef') should return 'ace'.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
N ested Loops and Lists: Write a Python function matrix_diagonal_sum that takes a 2D list (a list of lists) representing a square matrix and returns the sum of the elements on the main diagonal (from the top left to the bottom right).
defaultdict: Write a Python function group_by_length using collections.defaultdict that takes a list of words as input and returns a dictionary where each key is a word length, and each value is a list of words of that length. For example, group_by_length(['apple', 'bat', 'bar', 'at']) should return {5: ['apple'], 3: ['bat', 'bar'], 2: ['at']}.
Counter: Write a Python function most_common_element using collections.Counter that takes a list and returns the most common element and its count as a tuple. In case of a tie, return all the elements with the h i g h e s t c o u n t i n a l i s t o f t u p l e s . F o r e x a m p l e , most_common_element([1,2,2,3,3,4]) could return [(2, 2), (3, 2)].
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
N umPy (Indexing with Conditions): Create a function replace_negative that takes a NumPy array and replaces all negative values in the array with zero. Test this function with an array of your choice.
pandas (Data Manipulation): Given a pandas DataFrame containing columns ['Name', 'Age', 'Salary'], write a function age_salary_ratio that adds a new column AgeSalaryRatio to the DataFrame, which is the ratio of Age to Salary. Demonstrate this function with an example DataFrame.
pandas (Data Aggregation): Write a function average_score_by_department that takes a DataFrame with columns ['Department', 'EmployeeName', 'Score'] and returns a new DataFrame with the average score for each department.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Create: Write an SQL statement to create a table Employees with the following columns: EmployeeID (primary key), Name, DepartmentID, and Salary. Select: Write a query to select the names of all employees in the Sales department from the Employees table. Update: Write an SQL command to increase the salary of all employees in the Marketing department by 10%. Delete: Write a query to delete all employees from the Employees table who have not been assigned to a department. Join: Write a query that selects all employee names and their department names. Assume you have another table Departments with columns DepartmentID and DepartmentName. Join: Write a query that lists all employees, along with their department names, including those who do not belong to any department. Group By with Aggregate Functions: Write a query to find the average salary within each department in the Employees table. Employee Table: Department Table
Basic Variable N ame: Write a regular expression to match a variable name that starts with a letter and can include any combination of letters, digits, and underscores. (Easy) Email Validation: Create a regex that validates an email address, ensuring it has the format username@domain.com. The username part can contain letters, numbers, dots, hyphens, and underscores. The domain must contain at least one dot and cannot start with a dot. (Moderate) URL Parsing: Write a regex to extract the protocol, domain, and path from a URL. For example, for http://www.example.com/path/to/page, extract http, www.example.com, and /path/to/page. (Moderate) Hexadecimal Color Code: Write a regular expression to find hexadecimal color codes like #1a2b3c in a text. The color code must start with # followed by exactly 6 hexadecimal digits. (Moderate) Password Strength: C reate a regex to check the strength of a password. The password must be at least 8 characters long, contain a mix of upper and lower case letters, at least one number, and at least one special character (like !@#$ %^&*). (Challenging) IPv4 Address: Write a regex to validate an IPv4 address. Each of the four numbers should be between 0 and 255, separated by dots. Leading zeros should be excluded. (Challenging) ISB N Validation: Create a regex to validate a 10-digit or 13-digit ISBN number. The 10-digit ISBN format is 1-5 numeric characters, a dash, 4 numeric characters, a dash, a single numeric character or 'X', and another dash followed by a single numeric character. The 13-digit ISBN is similar but starts with 978 or 979. (Challenging) Date Format Conversion: Write a regex to find dates in the format DD/ MM/YYYY and convert them to YYYY-MM-DD format. (Challenging)
N ested Brackets: Create a regex to check if a string contains correctly nested and balanced parentheses, brackets, and braces. (Very Challenging) Complex Code Comment Removal: Write a regex to remove all comments from a snippet of code. Assume comments start with // and continue to the end of the line, and block comments are enclosed in /* */. The regex should handle nested comments correctly. (Very Challenging)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help