CSC108H5 Lecture Notes - Lecture 9: If And Only If

44 views2 pages
School
Course
897wjface and 39475 others unlocked
CSC108H5 Full Course Notes
12
CSC108H5 Full Course Notes
Verified Note
12 documents

Document Summary

Common_characters def common_characters(s1, s2): (str, str) -> bool. Given a string s1 and s2, return true iff all characters in s2 occur in s1. Attempt 1: only checks the first character for char in len(s2): # for loop wants a collection of things to iterate through, one by one. # range(4) gives me back a collection of numbers from 0 up to 4. # a string is a collection of characters. # that"s why i can do things like for i in range(4) or for ch in s. # but i can not do something like for i in 3, because a single number 3 is not something. # that i can go through one by one, that doesn"t make sense for char in s2: if char not in s1: return false else: return true. Attempt 2: shorter version of attempt 1 for char in s2: return char not in s1.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions