WGU C949 - Lists and Dicts Questions & Correct Answers | Grade A+WGU C949 - Lists and Dicts Questions & Correct Answers | Grade A+
list() Ans- Create an empty list var = [ 0, 1, 2 ] Ans- Create a list and initialize it with the supplied values list()[start:end:step] Ans- Slice the list and return a copy. 'start' is the first index to return in the result. 'end' is the last index to return in the result. 'step' indicates which values to pull into the sublist. A 'step' of 1 returns every element, 'step' of 2 every other element, 'step' of 3 is every third element and so on. alist = [ 0, 1, 2, 3, 4, 5 ] Slice Operation # Result sub_list_a = alist[1:] # [1, 2, 3, 4, 5] sub_list_b = alist[:-1] # [0, 1, 2, 3, 4] sub_list_c = alist[1:-1:2] # [1, 3] sub_list_d = alist[::2] # [0, 2, 4] list()[:] Ans- Return a copy of the list [ expression for item in source_list if condition ] Ans- List comprehension. Filter or generate a list from another list. Example: Get all even numbers in a list alist = [ 0, 1, 2, 3, 4, 5 ] result = [n for n in alist if n % 2 == 0] alist[index] Ans- Get the value for index from the lis
Geschreven voor
- Instelling
- WGU C949
- Vak
- WGU C949
Documentinformatie
- Geüpload op
- 15 juli 2024
- Aantal pagina's
- 6
- Geschreven in
- 2023/2024
- Type
- Tentamen (uitwerkingen)
- Bevat
- Vragen en antwoorden
Onderwerpen
-
wgu c949 lists and dicts questions correct an
Ook beschikbaar in voordeelbundel