Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 2 fuera de 7 páginas
Examen

CNIT 155 FINAL (PURDUE) QUESTIONS & ANSWERS

Document preview thumbnail
Vista previa 2 fuera de 7 páginas

CNIT 155 FINAL (PURDUE) QUESTIONS & ANSWERS

Vista previa del contenido

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

Información del documento

Subido en
24 de enero de 2026
Número de páginas
7
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas
$13.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
GEEKA
3.8
(360)
Vendido
2132
Seguidores
1446
Artículos
57748
Última venta
1 hora hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes