Adding items to a set

To add an item to a set, we have to use the insert() method. Let's use that to add another movie to Gabe's favorite movies:

gabesFavMovieSet.insert("Terminator") 
gabesFavMovieSet 

Your code should now look like this:

Now, Gabe has nine films, and Craig still has none. We added the gabeFaveMovieSet variable again so that we can see the contents update in the Results Panel. To add multiple items to a set, we can use an array literal.

Let's add ten films to Craig's list, as follows:

craigsFavMovieSet = ["The Pianist", "The Shawshank Redemption", "Dark Knight", "Black Swan", "Ip Man", "The Illusionist", "The Silence of the Lambs", "Winter Solider", "Green Mile", "Se7en"] 

Your code should now look like this:

Craig's set now has ten films. Next, let's look at how we can work with sets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.86.172