Question

In: Computer Science

In this homework, you are provided a user pool (hw2_users_4m.txt) and a list of target users...

In this homework, you are provided a user pool (hw2_users_4m.txt) and a list of target users (hw2_targets.txt). Find if each target user is in the user pool. In python

1. Use set to store user pool.

with open('hw2_users_4m.txt', 'r') as i:
    user_ids_set = {line.strip() for line in i}

start_time = time.time()
results_set = []
##################################
## write your code for using set
##################################


end_time = time.time()
run_time = end_time - start_time
print(round(run_time, 2))
with open('output_set.txt', 'w') as o:
    for result in results_set:
        o.write(result[0] + ',' + result[1])

Solutions

Expert Solution

Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.

Below is the output of the program:
Contents of hw2_users_4m.txt:


Contents of hw2_targets.txt:


Contents of output_set.txt:


Console output:

Below is the code to copy:

#CODE STARTS HERE----------------
import time
with open('hw2_users_4m.txt', 'r') as i:
    user_ids_set = {line.strip() for line in i}

start_time = time.time()
results_set = []
with open("hw2_targets.txt") as j: #open targets file
    for target in j.readlines(): #Read line by line
        if target.strip() in user_ids_set: #Check if target is in users set
            results_set.append((target.strip(),"persent")) #update result list with "present"
        else: #If not present
            results_set.append((target.strip(),"not present")) #update result list with "not present"

end_time = time.time()
run_time = end_time - start_time
print(round(run_time, 2))
with open('output_set.txt', 'w') as o:
    for result in results_set:
        o.write(result[0] + ',' + result[1]+'\n')
#CODE ENDS HERE-----------------

Related Solutions

In this homework, you are provided a user pool (hw2_users_4m.txt) and a list of target users...
In this homework, you are provided a user pool (hw2_users_4m.txt) and a list of target users (hw2_targets.txt). Find if each target user is in the user pool. In python 1. Use list to store user pool and write the output into a file. user_id_1,True user_id_2, False with open('hw2_targets.txt', 'r') as i: targets = [line.strip() for line in i] with open('hw2_users_4m.txt', 'r') as i: user_ids_list = [line.strip() for line in i] start_time = time.time() results_list = [] ################################## ## write your...
Design a Python script that accepts as input a user-provided list and transforms it into a...
Design a Python script that accepts as input a user-provided list and transforms it into a different list in preparation for data analysis, the transformed list replaces each numeric element in the original list with its base-10 order of magnitude and replaces string elements with blanks. Example: This script accepts as input a user-provided list expected to contain non-zero numbers and strings. It then prints a transformed list replacing numbers with their order of magnitude, and strings as blanks. Type...
In this homework, you will implement a single linked list to store a list of employees...
In this homework, you will implement a single linked list to store a list of employees in a company. Every employee has an ID, name, department, and salary. You will create 2 classes: Employee and EmployeeList. Employee class should have all information about an employee and also a “next” pointer. See below: Employee Type Attribute int ID string name string department int salary Employee* next Return Type Function (constructor) Employee(int ID, string name, string department, int salary) EmployeeList class should...
Thinking about the types of users: Internal and External users, How do each type of user...
Thinking about the types of users: Internal and External users, How do each type of user effect the accounting process in an organization? What types of users have the most impact and why? responses must be 100 words minimum.
For Homework 4, we are going to present the user with a series of menus, accept...
For Homework 4, we are going to present the user with a series of menus, accept as input the action they wish to take, and act appropriately. You must practice basic input validation to ensure that the menu option they chose is valid. Create “CPS132 Homework 4” project in Eclipse Create “Homework4.py” file Download "Homework4_incomplete.py" Paste the text into "Homeworkpy" Make sure to fill in the appropriate information in the header including your name, username, due date, Homework #4, and...
You are provided two problem statements below (Homework Problem 1). For each, provide a score on...
You are provided two problem statements below (Homework Problem 1). For each, provide a score on a scale of 1 to 10 with 10 being best. Provide justification for each score that you gave. Example Problem Statements 1. We want to improve employee performance in the Human Resources (HR) department. 2. We want to improve sales revenue by 10%.
For certain software, independently of other users, the probability is 0.07 that a user encounters a...
For certain software, independently of other users, the probability is 0.07 that a user encounters a fault. What are the chances of the 30th user is the 5th person encountering a fault?
Purpose For many users, the system is the user interface. Everyone wants a system that is...
Purpose For many users, the system is the user interface. Everyone wants a system that is easy to learn and use. It is the analyst’s responsibility to ensure that the user interface will be designed in a way to support the user’s interface needs.   In this milestone you will explore the guidelines for user interface design. The analyst must consider a variety of interface formats. These include how data gets entered into the system (input design) and how data or...
Choose a product you are familiar with. List the target market of that product, the behavior...
Choose a product you are familiar with. List the target market of that product, the behavior you would want consumers to do for that product, and the mental steps that may be necessary to move consumers to the behavior. Hint, here are some other mental steps/intervening variables, communication objectives in addition to awareness - knowledge of a benefit, preferring one brand over another
SQL Homework -- This script creates the schema named mgs -- Connect as the user named...
SQL Homework -- This script creates the schema named mgs -- Connect as the user named mgs --CONNECT cs270226mgs/mgs; -- Use an anonymous PL/SQL script to -- drop all tables and sequences in the current schema and -- suppress any error messages that may displayed -- if these objects don't exist BEGIN EXECUTE IMMEDIATE 'DROP SEQUENCE category_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE product_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE customer_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE address_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE order_id_seq'; EXECUTE IMMEDIATE 'DROP...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT