Initial work
This commit is contained in:
14
CS1032/practical-2023-10-04/workshop.py
Normal file
14
CS1032/practical-2023-10-04/workshop.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from typing import Iterable
|
||||
|
||||
def split(delim: str, s: str) -> Iterable[str]:
|
||||
while len(s):
|
||||
idx = s.find(delim)
|
||||
if idx == -1: idx = len(s)
|
||||
yield s[:idx]
|
||||
s = s[idx + len(delim):]
|
||||
|
||||
for x in split(", ", "Aberdeen, Dundee, Edinburgh, Glasgow"): print(x)
|
||||
|
||||
# Swap M and D names in the definitions
|
||||
d, m, y = tuple(split("/", "11/9/2001"))
|
||||
print(f"Day = {d}, Month = {m}, Year = {y}")
|
||||
Reference in New Issue
Block a user