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...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
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 lists are power data structures. Describe some of the benefits of Python lists" Make sure...
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure you don't just give me a list but a few sentences instead just answering it.
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...
Python I am creating a class in python. Here is my code below: import csv import...
Python I am creating a class in python. Here is my code below: import csv import json population = list() with open('PopChange.csv', 'r') as p: reader = csv.reader(p) next(reader) for line in reader: population.append(obj.POP(line)) population.append(obj.POP(line)) class POP: """ Extract the data """ def __init__(self, line): self.data = line # get elements self.id = self.data[0].strip() self.geography = self.data[1].strip() self.targetGeoId = self.data[2].strip() self.targetGeoId2 = self.data[3].strip() self.popApr1 = self.data[4].strip() self.popJul1 = self.data[5].strip() self.changePop = self.data[6].strip() The problem is, I get an error saying:  ...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT