Question

In: Computer Science

python 3 countries = ['mexico,'eseft,'ry,',ft,'us'] Write a statement that sorts the countries alphabetically and another statement...

python 3

countries = ['mexico,'eseft,'ry,',ft,'us']

Write a statement that sorts the countries alphabetically and another statement that prints the last country in the sorted nations list.

Solutions

Expert Solution

Answer:

To sort the given list in the alphabetically order there is the pre- defined function in the python 3 that is the sorted function which automatically sorts the list in the alphabetically order.

To print the last country of the sorted list there is 2 methods:

1. The first method is to directly pass the index of the last element of the list in the print statement.( The list will always start with the index 00.

2. The second method to find out with the help of the length of the list in the print statement.The length of the list can be find out by the pre-defined len function.

Here is the code of the program:

countries=['mexico','eseft','ry','ft','us']

#statement that prints the countries in the alphabetically order by the predefined function sorted.

sorted_countries=sorted(countries)

print("Sorted list :",sorted_countries)

# statement that prints the last country in the sorted list

print("By Index method:",sorted_countries[4]) # index will be 4 because the index of the string is started from 0

# Another method by which we can print the last country in the sorted list

length=len(countries)

# here the 1 is subtracted from the length because the index is started from 0

print("By length method:",sorted_countries[length-1])

* Please refer to the screenshot of the code for proper indentation:

Here is the screenshot of the code:

Here is the output of the code:


Related Solutions

Two countries: US and Mexico. Two goods: Airplane and car. A US worker's MPL is 20...
Two countries: US and Mexico. Two goods: Airplane and car. A US worker's MPL is 20 times higher than a Mexican worker in making an airplane. A US worker's MPL is 5 times higher than a Mexican worker in making a car. Which country has absolute advantage in making cars and why? Which country has comparative advantage in making cars and why?
Python 3 Function which takes the head Node of a linked list and sorts the list...
Python 3 Function which takes the head Node of a linked list and sorts the list into non-descending order. PARAM: head_node The head of the linked list RETURNS: The node at the head of the sorted linked list. ''' def sort(head_node): #Code goes here ''' Test code goes here '' ' if __name__ == '__main__':
3. The labor supply and demand equations in Mexico and the US are Ndmex = 140...
3. The labor supply and demand equations in Mexico and the US are Ndmex = 140 – 2 Wmex and Nsmex = 80 NdUS = 600 – 4 WUS and NsUS = 260 (Notice: To make the exercise simple, we are assuming that the labor supply curves are perfectly vertical at 80 in México and at 260 in the US). where Ndmex and NdUS are the number of workers demanded in Mexico and the US (in millions of workers). Wmex...
use python 1. Write a program that a. defines a list of countries that are members...
use python 1. Write a program that a. defines a list of countries that are members of BRICS (Brazil, Russia, India, China, Sri Lanka) b. Check whether a country is a member of BRICS or not Program run Enter the name of country: Pakistan Pakistan is not a member of BRICS Enter the name of country : India India is a member of BRICS 2. Write a program to create a list of numbers in the range of 1 to...
IN PYTHON: Write a program to study countries and their capitals. The program will store country:capital...
IN PYTHON: Write a program to study countries and their capitals. The program will store country:capital information and allow the user to quiz themselves. These two functions are required for this assignment. You may add other functions that you deem appropriate: - menu()   This function, which displays all the user options to the screen, prompts the user for their choice and returns their choice. This function will verify user input and ALWAYS return a valid choice. - addCapital(dict) This function...
using python: Given an arbitrary whole number, please write an if statement to output if it...
using python: Given an arbitrary whole number, please write an if statement to output if it is an even number or an odd number
Please use Python 3 3). Write a function that writes a series of random numbers to...
Please use Python 3 3). Write a function that writes a series of random numbers to a text file named ‘random_number.txt’. Each random number should be in the range of 1 through 500. The function should let the user specify how many random numbers the file will hold. Then write another function that reads the random numbers from the ‘random_number.txt’ file, displays the numbers, and then displays the total of the numbers and the number of random numbers read from...
***Please code in Python Write another code Newton (in double precision) implementing the Newton-Raphson Method   (copy...
***Please code in Python Write another code Newton (in double precision) implementing the Newton-Raphson Method   (copy your Bisect code and modify).   Evaluation of F(x) and F'(x) should be done in a subprogram FCN(x).   The code should ask for input of: x0, TOL, maxIT (and should print output similar to Bisect code).   Debug on a simple problem, like x2−3 = 0.   Then use it to find root of F(x) in [1,2] with TOL=1.e-12. Now consider the problem of finding zeros of      ...
Write the following Python script: Problem Statement A string X is an anagram of string Y...
Write the following Python script: Problem Statement A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which...
Question 3: getting diagnostics, Write a python program   Write the getting diagnostics function, which reports the...
Question 3: getting diagnostics, Write a python program   Write the getting diagnostics function, which reports the most frequent diagnostic from the patients with the highest symptoms similarity returned by the function similarity to patients. See below for an explanation of exactly what is expected. def getting_diagnostics(patient_set : Set[int], diagnostic_by_patient: Dict[int, str]) -> str: """ Returns a string representing the most frequent diagnostic from the set of diagnostics (stored in the dictionary diagnostic_by_patient) of the patient_set (that is a set of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT