Question

In: Computer Science

how to use subsetting in Python lists. Practice making subsets of the namelist. import matplotlib.pyplot as...

how to use subsetting in Python lists. Practice making subsets of the namelist.

import matplotlib.pyplot as plot

# set up your lists

numlist = [8, 6, 5, 3]

namelist = ['freshmen', 'sophomores', 'juniors', 'seniors']

colorlist = ['red', 'green', 'pink', 'yellow' ]

explodelist = [0.1, 0.0, 0.0, 0.0]

# make the pie chart

plot.pie(numlist, labels=namelist, autopct='%.2f%%', colors=colorlist,

        explode = explodelist, startangle = 90)

plot.axis('equal')

plot.savefig('piechart.png')

Solutions

Expert Solution

ANSWER : HERE IS THE ANSWER FOR YOUR QUESTION:

----------------------------------------------------------------------------------------------------------------

               CODE:

import matplotlib.pyplot as plot

# set up your lists

numlist = [8, 6, 5, 3]



namelist = ['freshmen', 'sophomores', 'juniors', 'seniors']

colorlist = ['red', 'green', 'pink', 'yellow' ]

explodelist = [0.1, 0.0, 0.0, 0.0]

# make the pie chart

plot.pie(numlist, labels=namelist, autopct='%.2f%%', colors=colorlist,

        explode = explodelist, startangle = 90)

plot.axis('equal')

plot.savefig('piechart.png')

#making subsets of the namelist using slicing operator (:)


print("the main list is " +str(namelist))

print("List with first 2 indeces is :" + str(namelist[:2]))

print("List with first 3 indeces is :" + str(namelist[:3]))

print("List with last 2 indeces is :" + str(namelist[2:]))

----------------------------------------------------------------------------------------------------------------

SNIPPET:

----------------------------------------------------------------------------------------------------------------

OUTPUT:

----------------------------------------------------------------------------------------------------------------

I hope this would help you out.

If you like my answer , please upvote

If you have any doubt, you can provide comment /feedback below the answer

Thanks


Related Solutions

Python Programming- Practice Lists & Tuples B #This is a template for practicing mutability and conversion...
Python Programming- Practice Lists & Tuples B #This is a template for practicing mutability and conversion #Create and assign the following list of numbers to a list data type and variable name: 99.9,88.7,89,90,100 #convert the list to a tuple and assign the tuple a different variable name #Ask the user for a grade and convert it to a float type (no prompt) and assign it to a new variable name #append the user entered grade to the list #update the...
Python Practice Sample: Generate lists containing the numbers between 1 and 50 as follows:  same...
Python Practice Sample: Generate lists containing the numbers between 1 and 50 as follows:  same is a list of all the two-digit numbers whose digits are the same (11, 22, etc.)  addsto6 is a list of all numbers the sum of whose digits is 6  rest contains the rest of the numbers. A number can appear only in one of the lists; with same having higher priority. (So for example, 33 would appear in the same, but...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the question above in a few sentences.
In Python This assignment involves the use of text files, lists, and exception handling and is...
In Python This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>>   Enter gender...
PYTHON...... Working with lists, functions, and files Objective: Work with lists Work with lists in functions...
PYTHON...... Working with lists, functions, and files Objective: Work with lists Work with lists in functions Work with files Assignment: Part 1: Write a program to create a text file which contains a sequence of test scores. Ask for scores until the user enters an empty value. This will require you to have the scores until the user enters -1. After the scores have been entered, ask the user to enter a file name. If the user doesn’t not enter...
Can anyone use python to solve this problem: Part B: List of lists The aim of...
Can anyone use python to solve this problem: Part B: List of lists The aim of Part B is to learn to work with list of lists. You may want to open the file lab05b_prelim.py in the editor so that you can follow the task description. The first part of the file lab05b_prelim.py defines a variable called datasets. The variable datasets is a list of 4 lists. This part consists of 2 tasks. Task 1: We ask you to type...
Use PYTHON --Nested Lists and DateTime Module. Write a program that does the following: Reads information...
Use PYTHON --Nested Lists and DateTime Module. Write a program that does the following: Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster...
The first random number generator comes from Python itself. To use it you need to import...
The first random number generator comes from Python itself. To use it you need to import the Python package. Then call the random() method. See below. import random print (random.random()) It is important to know that a random number generator really is random. If so, it should have uniform distribution between 0 and 1. Test the random number generators in Python for uniformity.
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT