Note that there are some explanatory texts on larger screens.

plurals
  1. POI need help pulling out specific data from a list of dictionaries
    primarykey
    data
    text
    <p>I have a text file that lists the first and last names of a set of employees, their ID numbers, genders and years of experience. The first line contains the number of employees. It's called employees.txt. Here it is:</p> <p>7</p> <p>John</p> <p>Doe</p> <p>33</p> <p>272838</p> <p>M</p> <p>Mary</p> <p>Johnson</p> <p>38</p> <p>3849383</p> <p>F</p> <p>Opie</p> <p>Dog</p> <p>6</p> <p>839293</p> <p>M</p> <p>Missy</p> <p>Dog</p> <p>4</p> <p>238392</p> <p>F</p> <p>John</p> <p>Bla</p> <p>28</p> <p>834282</p> <p>M</p> <p>Amelia</p> <p>Spien</p> <p>2</p> <p>5789812</p> <p>F</p> <p>Shane</p> <p>CasenStien</p> <p>2</p> <p>567891</p> <p>M</p> <hr> <p>I want to organize this information into a list of dictionaries and then find all the female employees and print out their first and last names. I can get the list of dictionaries to work, but I'm getting an error when I try to find and print out the names of the female employees. Here's my code:</p> <pre><code>def employee_write(file): employee_dict = {} employee_dict["First"] = file.readline().strip() employee_dict["Last"] = file.readline().strip() employee_dict["Experience"] = file.readline().strip() employee_dict["ID"] = file.readline().strip() employee_dict["Gender"] = file.readline().strip() return employee_dict def female_print(x2): for term in x2: for word in employee_dict: if employee_dict["Gender"] == "F": print(employee_dict["First"]) print(employee_dict["Last"]) def main(): file = open("employees.txt", "r") n = int(file.readline()) x1 = employee_write(file) employee_list = [] for i in range(n): employee_list.append(x1) x2 = employee_list print(x2) female_print(x2) main() </code></pre> <p>What is my error here? The female_print() function is not working because it says that the name 'employee_dict' is not defined. What's the problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload