Question

The python code required is for a text file that has names and numbers associated with...

The python code required is for a text file that has names and numbers associated with those names e.g.( GARCIA   0.31817:)

infile = open('last.txt', 'r') - the file must be read only

for line in infile:

the question is this:

Find the name that comes first in the dictionary (alphabetical) order and assign it to “ans13” variable.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
infile = open('last.txt', 'r')

ans13 = None
for line in infile:
    words = line.strip().split()
    if ans13 is None or words[0] < ans13:
        ans13 = words[0]
infile.close()  # remove this line if closing the file is not required.
# print(ans13)  # uncomment this line if you want to print ans13
Add a comment
Know the answer?
Add Answer to:
The python code required is for a text file that has names and numbers associated with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • QUESTION17 The following Python script aims to read lines from a text file and add them...

    QUESTION17 The following Python script aims to read lines from a text file and add them to a list Marlout oft. 00 Example P Flag question If the text file contains the following lines wordt wordz words the list will be ['word, word2, Words' after the execution of the program Question: Rearrange the following statements on the correct (logical) form Note: The-indicates the indentation #--> Program infile=onen/fileName --infile = open(fileName, 'r') . . -try: --for line in infile: --infile =...

  • (Python 3) Write a program that reads the contents of a text file. The program should...

    (Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...

  • write a function: Names(path): that reads from a file at location path and returns a dictionary...

    write a function: Names(path): that reads from a file at location path and returns a dictionary mapping from column names to lists containing the data in those columns. The format of the file is a csv file. The first line is a comma separated set of string names for the columns contained in the file. The function will accumulate a dictionary mapping from year to the list of years, from name to the list of names (in the same order),...

  • Create a python code named LetterCount with a text file named words.txt that contains at least...

    Create a python code named LetterCount with a text file named words.txt that contains at least 100 words in any format - some words on the same line, some alone (this program involves no writing so you should not be erasing this file). Then create a program in the main.py that prompts the user for a file name then iterates through all the letters in words.txt, counting the frequency of each letter, and then printing those numbers at the end...

  • Write a Python program to read lines of text from a file. For each word (i.e,...

    Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...

  • program must be written in python and have commentary. thank you 3. File Encryption and Decryption...

    program must be written in python and have commentary. thank you 3. File Encryption and Decryption Write a program that uses a dictionary to assign "codes" to each letter of the alphabet. For example: codes-{A':'8','a' :'9', 'B' : e','b' :'#,, etc ) Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol e, and so forth. The program should open a...

  • Python 3.7 Coding assignment This Program should first tell users that this is a word analysis...

    Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....

  • in python in the simplest way I have a file “a.txt” under the directory /temp/, the...

    in python in the simplest way I have a file “a.txt” under the directory /temp/, the file contains some company names, the format is like that: IBM APPLE cisco Microsoft …… Each line contains only one company name. Among these company names, some are capitalized such as IBM, APPLE, some are not, such as cisco. Write a program to read this file a.txt and convert all names to uppercase and save them to the file name “b.txt” in the same...

  • *PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code...

    *PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code function. Good answers will be rated with thumbs up! Please answer both parts. Thank you for your time. Question 3 - Suppose you have a file named numbers.csv which contains a bunch of integers, five per line of text, separated by commas. Write code below that will open the _le, read the numbers from it, and print the sum of all the even numbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT