Deletion of List Elements
a = ['one', 'two', 'three']
del a[1]
for s in a:
print(s)
b = ['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b']
del b[1:5]
print(b)
b.remove('a')
print(b)
# Output:
'''
one
three
['a', 'f', 'a', 'b']
['f', 'a', 'b']
'''
Reference Variables
list1 = [1, 2, 3, 4] list2 = list1[:] print(list1 is list2) # False print(list1 == list2) # True
Lists and Functions
# CS 110A - Starting poing for in-class exercise on List References and Functions
def main():
a = []
inputList(a)
print("Here are the names you entered (excluding Craig):")
for item in a:
print(item)
# Insert your code here
# Write the inputList function so that the program produces the output below.
main()
# Sample output:
'''
Please input one name on each line, hitting Enter on a blank line when finished:
Craig
Indika
Deepa
Man
Here are the names you entered (excluding Craig):
Indika
Deepa
Man
'''
'''
Please input one name on each line, hitting Enter on a blank line when finished:
Erez
Dan
Craig
Anita
Henry
Here are the names you entered (excluding Craig):
Erez
Dan
Anita
Henry
'''
def main():
a = [] # creating empty list
inputList(a) # calling method below
print("Here are the names you entered (excluding Craig):")
for item in a:
print(item) # printing elements of modified list a
# Insert your code here
# inputlist function that takes empty list, asks user to enter
names, store them in list and removes Craig from it
def inputList(a):
print('Please input one name on each line, hitting Enter on a blank
line when finished:') # printing instruction
name = raw_input(); # taking input name
while ( name !=''): # looping until user presses Enter (name = ''
)
a.append(name) # this functions adds new element (name) to list
a
name = raw_input(); # taking input again
a.remove('Craig') # removing first occurance of name 'Craig'
main()

Sample outputs:


Deletion of List Elements The del statement removes an element or slice from a list by position....
Write a Python program (remove_first_char.py) that removes the first character from each item in a list of words. Sometimes, we come across an issue in which we require to delete the first character from each string, that we might have added by mistake and we need to extend this to the whole list. Having shorthands (like this program) to perform this particular job is always a plus. Your program should contain two functions: (1) remove_first(list): This function takes in a...
Something is preventing this python code from running properly.
Can you please go through it and improve it so it can work. The
specifications are below the code. Thanks
list1=[]
list2=[]
def add_player():
d={}
name=input("Enter name of the player:")
d["name"]=name
position=input ("Enter a position:")
if position in Pos:
d["position"]=position
at_bats=int(input("Enter AB:"))
d["at_bats"] = at_bats
hits= int(input("Enter H:"))
d["hits"] = hits
d["AVG"]= hits/at_bats
list1.append(d)
def display():
if len(list1)==0:
print("{:15} {:8} {:8} {:8} {:8}".format("Player", "Pos", "AB",
"H", "AVG"))
print("ORIGINAL TEAM")
for x...
Need help solving this qestion related to object and item classes involving arrays in PYTHON. Classes and Object - Inventory Item as Object In this assignment the idea is to use an Item class to capture what you need for recording and displaying the details of an order from an online store like Amazon. This is a Class and Object assignment. For the assignment you must define and implement the Item class so that the code shown immediately below can...
C++ LAB 19 Construct functionality to create a simple ToDolist. Conceptually the ToDo list uses a structure called MyToDo to hold information about each todo item. The members of the MyToDo struct are description, due date, and priority. Each of these items will be stored in an array called ToDoList. The definition for the MyToDo struct should be placed in the header file called ToDo.h Visually think of the ToDoList like this: There are two ways to add items to...
This class implements a doubly linked list in which the nodes are of the class DLNode. This class must implement the interface DLListADT.java that specifies the public methods in this class. The header for this class will then be public class DLList implements DLListADT This class will have three private instance variables: • private DLNode front. This is a reference to the first node of the doubly linked list. • private DLNode rear. This is a reference to the last...
Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The BankAccount class declaration in file BankAccount.java is the blueprint of a BankAccount object. Check out the design of a BankAccount class. 1. In BankAccount.java class, all of the method stubs ( methods with a header but empty bodies ) are present to help you get started. Your task is to complete the method bodies. All comments in red in the diagram above indicates what...
I NEED HELP WITH THIS HOMEWORK!!!! What is a characteristic of a bag data type? Elements are added and removed in any order Elements are removed in the same order they were added Distinct elements are added in any order but are removed beginning with the last one added Distinct elements are removed in the reverse order they were added Which scenario illustrates a data stack structure Standing in a line to be serviced Filing documents in alphabetical order Offering...
Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....
c++ only Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we’ll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct Node { int number; Node * nextNode;...
D Question 12 1.5 pts Check the true statements about NumPy arrays: O A single instantiated NumPy array can store multiple types (e.g., ints and strings) in its individual element positions. A NumPy array object can be instantiated using multiple types (e.g., ints and strings) in the list passed to its constructor O Memory freeing will require a double-nested loop. The number of bits used to store a particular NumPy array object is fixed. O The numpy.append(my.array, new_list) operation mutates...