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
murzikaleks [220]
4 years ago
11

#Write a function called alter_list. alter_list should have#two parameters: a list of strings and a list of integers.##The list

of integers will represent indices for the list of#strings. alter_list should alter the capitalization of all#the words at the designated indices. If the word was all#capitals, it should become all lower case. If it was all#lower case, it should become all capitals. You may assume#that the words will already be all-caps or all-lower case.##For example:## string_list = ["hello", "WORLD", "HOW", "are", "you"]# index_list = [0, 2]# alter_list(string_list, index_list) -> # ["HELLO", "WORLD", "how", "are", "you"]##After calling alter_list, the strings at indices 0 and 2#have switched their capitalization. ##Note that it may be the case that the same index is present#in the second twice. If this happens, you should switch the#text at that index twice. For example:## string_list = ["hello", "WORLD", "HOW", "are", "you"]# index_list = [0, 2, 2]# alter_list(string_list, index_list) -> # ["HELLO", "WORLD", "HOW", "are", "you"]##2 is in index_list twice, so the string at index 2 is#switched twice: capitals to lower case, then back to#capitals.#Write your function here!#Below are some lines of code that will test your function.#You can change the value of the variable(s) to test your#function with different inputs.##If your function works correctly, this will originally#print:#["hello", "WORLD", "HOW", "are", "you"]#["HELLO", "WORLD", "HOW", "are", "you"]print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2]))print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2, 2]))
Computers and Technology
1 answer:
Aleks04 [339]4 years ago
7 0

Answer:

The Python code is given below with appropriate comments

Explanation:

def alter_list(strings,index):

   

   for i in index:

       s = strings[i]

       if s.islower():  #checking if lowercase

           strings[i] = s.upper()  #assigning variable in strings to uppercase in s

           

       if s.isupper():  #checking if uppercase

           strings[i] = s.lower()  #assigning variable in strings to lowercase in s

   return strings  #returns strings for the function

           

print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2]))

print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2, 2]))

You might be interested in
If you want a relatively broad, unbiased overview of a subject you should consult a/an ?
tekilochka [14]

To find a relatively broad unbiased overview of a subject in a specific field of study, it would be best to consult a: encyclopedia.
8 0
3 years ago
Read 2 more answers
There are 5 houses in a row and in 5 different colors.
tankabanditka [31]
What’s the question?
5 0
4 years ago
Help with prg 140 class it is really giving me a hard time understanding it<br>​
Snowcat [4.5K]

Answer:

post your homework so we can help you.

Explanation:

8 0
3 years ago
The front page of Reddit is "democratic" because:
Rina8888 [55]
The people of Reddit vote for what they want seen and heard, the people of Reddit vote for something that represents them using upvotes.
3 0
4 years ago
Read 2 more answers
How is the cia triad used to evaluate encryption methods?
Lyrx [107]

Answer:

The CIA triad is an important concept in data security, which helps to prevent data from being seen by unauthorized parties, changed, and provide uninterrupted access to data when needed.

Explanation:

CIA triad stands for confidentiality, integrity, and availability. confidentiality is a concept in the triad that prevents unauthorized users from seeing the data, by access control and encrypting the data using various algorithms.

The Integrity of the data prevents the change of the data by unauthorized users. It uses an algorithm for drafting a calculative check to compare the actual data sent and the data received.

Availability tries to break the barrier of data shortage or data unreachable events, by providing multiple access or fault tolerance to data storage.

6 0
4 years ago
Other questions:
  • Using a loop, write a program that reads in exactly five integers and outputs the sum.
    11·1 answer
  • Who gave a demonstration of modern computer systems showing a mouse and when?
    8·1 answer
  • Which resource do programmers sometimes have to refer to and use during planning the logical steps of the solution?
    10·2 answers
  • At the frequency of 2.4 GHz what is the free-space path loss in dB.
    9·1 answer
  • The amount of ram that is actually on the memory modules in your computer is the ________ memory.
    11·1 answer
  • If you have a 99% and you got a 50 on a test what is the grade please I will give brainless
    7·2 answers
  • Hide Time Remaining A
    11·1 answer
  • Use the drop-down tool to match each definition to the correct word or phrase. The computer that responds to requests from the c
    15·1 answer
  • Suppose you have a string matching algorithm that can take in (linear)strings S and T and determine if S is a substring (contigu
    11·2 answers
  • In addition to letting people share files, what is the most useful feature of
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!