WELCOME Overview 1. Exercise 2 Feedback 01101000 01101001 2. Lecture Material Review: 00100001 1. Python re module 2. Tuples 3. Sets 4. Nested lists 5. Wikipedia module
3. Quizizz! Exercise 2 Feedback
Task 2 : a = int(input("Enter the value of a: "))
Task 4 : Tip: use of lists to store the suffixes and
use of str.endswith() method Example = masc_suffixes = ["smus", "ner", "ich", "ist"]
if noun.endswith(masc_suffixes): # the noun is masculine print("The noun is masculine. -> der " + noun)
Task 5 : count < n safer option than count != n
Tuples ● Ordered set of values () ● Immutable = CANNOT modify the values once created ● Elements can have any type ● Access elements via index or slice ● Iterable Sets ● Unordered collection of unique values ● Empty: set() ● With values: {1, 2, 3} ● Iterable ● Mutable ● Operations like add(),remove(),&,| etc. ● Construct a set from a list or tuple by set() Sets: Union, Intersection and Difference set_1 | set_2 set_1 - set_2 set_1.union(set_2) set_1.difference(set_2)
set_1 & set_2
set_1.intersection(set_2) Some Built-in Functions: Tuples Sets Nested Lists A list can contain any sort object, even another list (sublist), which in turn can contain sublists themselves, and so on... Wikipedia Module Installation pip install wikipedia Import import wikipedia Searching results = wikipedia.search("Python programming") Summary summary = wikipedia.summary("Python programming", sentences=1) Language setting wikipedia.set_lang("es") # Sets to Spanish. Use 'en' for English, 'de' for German, etc.