Flashcards
List Methods
Flashcards do conjunto (10)
- 11.Check that x is not in lst listif x not in lst
- 2List lst repeated n timesprint (lst * n)
lst *= n - 3Sum of list elements (for numeric values)sum(lst)
- 41.Add x to the end of the lst list 2.Insert element x at position lst[i]. Elements to the right of the insertion change index to i + 1lst.append(x)
lst.insert(i, x) - 5lst1 = [2, 7] lst2 = [4, 6] lst1.extend(lst2) print(lst1)[2, 7, 4, 6]
The elements of the list lst2 are added to the end of the list lst1, i.e. list expansion lst1 - 6lst=[4,8,9] Removes the 2-th element of the listdel lst[2]
- 7nums = [9, 7, 4, 6] del nums[:2] print(nums)[4, 6]
- 8Delete the first occurrence of x in lst, in case x not in lst - an errorlst.remove(x)
- 9nums = [9, 7, 4, 6] nums.reverse() print(nums)[6, 4, 7, 9]
- 101.nums = [9, 7, 4, 6] nums.sort(reverse=True) print(nums) 2.nums = [9, 7, 4, 6] nums.sort() print(nums)1. [9, 7, 6, 4]
Sort the list in descending order
2.[4, 6, 7, 9]
Informações
- Descrição
- FlashCards sobre List Methods, criado por Ainagul Ermekova em 07-01-2025.
- Criado por
- Ainagul Ermekova
- Visualizações
- 1
- Avaliação