Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 2 out of 7 pages
Exam (elaborations)

CNIT 155 FINAL (PURDUE) QUESTIONS & ANSWERS

Document preview thumbnail
Preview 2 out of 7 pages

CNIT 155 FINAL (PURDUE) QUESTIONS & ANSWERS

Content preview

CNIT 155 FINAL (PURDUE) QUESTIONS & ANSWERS


Two Ways to Create an Empty List: - Answers -list1 = [ ]
list1 = list ()

How to Create a List? - Answers -Put a sequence of items in [ ]

Ex. colors = ["red", "yellow", "blue"]

Reading 10 Values from a User then Finding the Minimum - Answers -values = [ ]
for i in range (0, 10):
v1 = int(input("Enter a value"));
values.append(v1);

print(values)
print(min(values))

Three Methods of Adding Elements to a List - Answers -list1.append(elem)
(adds a single element to the end of the list)

list1.insert(index,elem)
(inserts the elem at the given index, shifting elements to the right)

list1.extend(list2)
(adds the elements in list2 to the end of the list)

Access an Individual Element in a List Using an Index - Answers -list1[index]

Positive Indexes - Answers -- First element in the list has index 0
- Second element has index 1
-n'th element is n-1

Negative Indexes - Answers -- Index -1 identifies the last element
- -2 identifies the next to last element, etc.

Built-In List Functions in Python - Answers -function - description
len - returns the number of items in the list
min - returns the min among the elements in the list
max - returns the max among the elements in the list
sum - returns the sum of all elements in the list

Shuffle Function - Answers -from random import shuffle
shuffle(list1)

, How to Call Methods Provided by a List - Answers -list.methodName(arguments)

Traversing a List - Answers -for index in range (len(scores)):
print (index, "\t" , grade[i])

for index, grade in enumerate(scores):
print (index, "\t" ,grade[index])

To add a whole list to the end, use the extend method: - Answers -scores.extend([55,
88, 79])
# gives [85,72,56,98,84,72,55,88,79]

Inserting an element at a given location: - Answers -Names.insert (2, "Hanah")

Inserting a new element at position 2 in the list

Deleting an from a list by index - Answers -del list[index]

Deleting a list range by using a slice - Answers -del list[2:5]

Deleting a specific value from a list - Answers -colors.remove("blue")

or

if "blue" in colors:
pos = colors.index("blue")
del colors[pos]

Reversing a list - Answers -list1.reverse()

Sorting a list (ascending order) - Answers -scores = [75, 63, 92]
scores.sort()
print(scores) # gives [63, 75, 92]

Sorting a list (descending order) - Answers -scores = [75, 63, 92]
scores.sort(reverse = True)
print(scores) #gives [92, 75, 63]

ordered_list = sorted(scores)
#to store the new list

Splitting a String - Answers -list = "one two three".split()

Replication - Answers -list = [0] * 100

Document information

Uploaded on
January 24, 2026
Number of pages
7
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$13.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
GEEKA
3.8
(360)
Sold
2132
Followers
1446
Items
57752
Last sold
2 hours ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions