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
Written for
- Institution
- WGU C949
- Module
- WGU C949
Document information
- Uploaded on
- July 15, 2024
- Number of pages
- 6
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
wgu c949 lists and dicts questions correct an
Also available in package deal