GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — programmingWithPythonCode/collections/lists_3.py at main · thomasWeise/programmingWithPythonCode

Expand file tree

/

lists_3.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
26 lines (19 loc) · 1.1 KB
/

lists_3.py

Copy path

File metadata and controls

26 lines (19 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""An example of more operations with lists."""
lst1: list[int] = [1, 2, 3, 4] # create first list
lst2: list[int] = [5, 6, 7] # create second list
lst3: list[int] = lst1 + lst2 # lst3 = concatenation of lst1 and lst2.
print(f"lst3 = lst1 + lst2 == {lst3}") # [1, 2, 3, 4, 5, 6, 7]
lst4: list[int] = lst2 * 3 # lst4 = lst2, repeated three times.
print(f"lst4 = lst2 * 3 == {lst4}") # [5, 6, 7, 5, 6, 7, 5, 6, 7]
lst5: list[int] = lst4[2:-2] # lst5 = lst4 from index 2 to 3rd from end
print(f"lst5 = lst4[2:-2] == {lst5}") # [7, 5, 6, 7, 5]
lst6: list[int] = lst4[1::2] # start at index 1, take every 2nd element
print(f"lst6 = lst4[1::2] == {lst6}") # [6, 5, 7, 6]
# Start copying lst4 at last element, move backwards take every 2nd
# element, and stop right before index=3.
lst7: list[int] = lst4[-1:3:-2]
print(f"lst7 = lst4[-1:3:-2] == {lst7}") # [7, 5, 6]
lst7[1] = 12 # Modify the slice lst7 originally from lst4.
print(f"{lst4 = }, {lst7 = }") # Shows that lst4 remains unchanged.
a, b, c = lst2 # store the three elements of lst2 into variables
print(f"{a = }, {b = }, {c = }") # a=5, b=6, c=7
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.