1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lora16 [44]
3 years ago
9

Python program

Computers and Technology
1 answer:
Serhud [2]3 years ago
7 0

Answer:

The function in Python is as follows:

def search_file(filename,mystring):

my_dict = {}

count = 0

file = open(filename)

lines = file.readlines()

for line in lines:

 count+=1

 if mystring.lower() in line.lower():

  my_dict[count] = line.rstrip('\n')

return my_dict

Explanation:

This defines the function

def search_file(filename,mystring):

This initializes an empty dictionary

my_dict = {}

This initializes the number of lines to 0

count = 0

This opens the file

file = open(filename)

This reads the lines of the file

lines = file.readlines()

This iterates through the lines

for line in lines:

This increments the number line

 count+=1

This checks if the string exists in the line

 if mystring.lower() in line.lower():

If yes, the line number and the string are added to the dictionary

  my_dict[count] = line.rstrip('\n')

This returns the dictionary

return my_dict

You might be interested in
You plan to use the Fill Down feature on a formula and you need to keep a cell reference the same. Which of the following format
yKpoI14uk [10]
A $E19 I now it because I am in college
6 0
3 years ago
Read 2 more answers
How do we benefit from this increased interconnectivity?
ankoles [38]
Well we just benefit from it like it just helps as I guess
8 0
3 years ago
What should the shutter speed be on the camera?<br> A. 1/30<br> B. 1/50<br> C. 1/60<br> D. 1/15
11Alexandr11 [23.1K]

Answer:

C. 1/60

Explanation:

Shutter speed is most commonly measured in fractions of a second, like 1/20 seconds or 1/10 seconds. Some high-end cameras offer shutter speeds as fast as 1/80 seconds. But, shutter speeds can extend to much longer times, generally up to 30 seconds on most cameras.

But in this case C. 1/60 is the answer.

6 0
3 years ago
At _________ the ip header is exposed and so filtering or firewalls can be applied to ip addresses. select one:
zvonat [6]
T<span>he IP packet header is what tells an IP-based host what to do with the packet that was received. 
</span>The TCP/IP<span> model describes the </span>protocols used by the Internet. The third layer is the Network layer and in the case of the Internet (the Internet Protocol IP). <span>The </span>Internet layer<span> is responsible for addressing, packaging, and routing functions.</span>
At layer 3 the IP header is exposed and so filtering or firewalls can be applied to IP addresses. 
7 0
3 years ago
What is personal computer?
Deffense [45]
A personal computer is a computer designed to be used by one person at a time.
7 0
3 years ago
Read 2 more answers
Other questions:
  • What are the 6 external parts of a computer system
    8·1 answer
  • How do computers find servers, requests information from the server, and receives it?
    12·1 answer
  • HURRY!! Ill give brainily and 25 points. Describe how Scent is related to the culture and historical period when it was created.
    15·1 answer
  • Direct connections provide continuous access to the Internet. Many bandwidth options are associated with direct connections. Whi
    9·1 answer
  • If none of the contacts of a manual switch change status when the operator is activated, what is the most probable cause?
    9·1 answer
  • 12. Kelly would like to know the average bonus multiplier for the employees. In cell C11, create a formula using the AVERAGE fun
    7·1 answer
  • Suppose that a disk drive has 5,000 cylinders, numbered 0 to 4,999. The drive is currently serving a request at cylinder 2,050,
    14·1 answer
  • Data aggregate functions
    6·1 answer
  • A file name extension provides what information about a file?
    6·1 answer
  • You're making great progress on your assignment. You've defined the purpose of your message, identified both the primary and sec
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!