What is the command to find out which lines in the My_list file contain the word foot?
Chapter 2 Python Lists Learn to store, access, and manipulate data in lists: the first step toward efficiently working with huge amounts of data.
https://projector-video-pdf-converter.datacamp.com/735/chapter2.pdf
5 Python Lists
6 Subsetting Lists
5 Manipulating Lists
Create a listtype: NormalExercise key: e6c527bf41 lang: python xp: 100 skills: - 2 As opposed to
After measuring the height of your family, you decide to collect some information on the house you're living in. The areas of the different parts of your house are stored in separate variables for now, as shown in the script.
Create list with different typestype: NormalExercise key: 1702a8bcdc lang: python xp: 100 skills: - 2 A list can contain any Python type. Although it's not really common, a list can also contain a mix of Python types including strings, floats, booleans, etc. The printout of the previous exercise wasn't really satisfying. It's just a list of numbers representing the areas, but you can't tell which area corresponds to which part of your house. The code in the editor is the start of a solution. For some of the areas, the name of the corresponding room is already placed in front. Pay attention here!
Select the valid listtype: MultipleChoiceExercise key: 416b80a405 lang: python xp: 50 skills: - 2 A list can contain any Python type. But a list itself is also a Python type. That means that a list can also contain a list! Python is getting funkier by the minute, but fear not, just remember the list syntax:
Can you tell which ones of the following lines of Python code are valid ways to build a list? A.
List of liststype: NormalExercise key: 9158c577b0 lang: python xp: 100 skills: - 2 As a data scientist, you'll often be dealing with a lot of data, and it will make sense to group some of this data. Instead of creating a flat list containing strings and floats, representing the names and areas of the rooms in your house, you can create a list of lists. The script in the editor can already give you an idea. Don't get confused here:
Subsetting Liststype: VideoExercise key: c076b5a69c xp: 50
Subset and conquertype: NormalExercise key: c3ce582e32 lang: python xp: 100 skills: - 2 Subsetting Python lists is a piece of cake. Take the code sample below, which creates a list
Remember the
Subset and calculatetype: NormalExercise key: 58c969f11f lang: python xp: 100 skills: - 2 After you've extracted values from a list, you can use them to perform additional calculations. Take this
example, where the second and fourth element of a list
Slicing and dicingtype: NormalExercise key: 7f08642d18 lang: python xp: 100 skills: - 2 Selecting single values from a list is just one part of the story. It's also possible to slice your list, which means selecting multiple elements from your list. Use the following syntax: The The code sample below shows an example. A list with
The elements with index 1 and 2 are included, while the element with index 3 is not.
Slicing and dicing (2)type: NormalExercise key: dfc9a168a3 lang: python xp: 100 skills: - 2 In the video, Hugo first discussed the syntax where you specify both where to begin and end the slice of your list: However, it's also possible not to specify these indexes. If you don't specify the
Subsetting lists of liststype: MultipleChoiceExercise key: dbbbd306cf lang: python xp: 50 skills: - 2 You saw before that a Python list can contain practically anything; even other lists! To subset lists of lists, you can use the same technique as before: square brackets. Try out the commands in the following code sample in the IPython Shell:
What will
Manipulating Liststype: VideoExercise key: d7fe818b3a xp: 50
Replace list elementstype: NormalExercise key: 4e1bba1b55 lang: python xp: 100 skills: - 2 Replacing list elements is pretty easy. Simply subset the list and assign new values to the subset. You can select single elements or you can change entire list slices at once. Use the IPython Shell to experiment with the commands below. Can you tell what's happening and why?
For this and the following exercises, you'll continue working on the
Extend a listtype: NormalExercise key: ff0fe8d967 lang: python xp: 100 skills: - 2 If you can change elements in a list, you sure want to be able to add elements to it, right? You can use the
You just won the lottery, awesome! You decide to build a
poolhouse and a garage. Can you add the information to the
Delete list elementstype: MultipleChoiceExercise key: 85f792356e lang: python xp: 50 skills: - 2 Finally, you can also remove elements from your list. You can do this with the
Pay attention here: as soon as you remove an element from a list, the indexes of the elements that come after the deleted element all change! The updated and extended version of
There was a mistake! The amount you won with the lottery is not that big after all and it looks like the poolhouse isn't going to happen. You decide to remove the corresponding string and float from the The
Which of the code chunks will do the job for us?
Inner workings of liststype: NormalExercise key: af72db9915 lang: python xp: 100 skills: - 2 At the end of the video, Hugo explained how Python lists work behind the scenes. In this exercise you'll get some hands-on experience with this. The Python code in the script already creates a list with the name If you want to prevent changes in
What command lets you view the contents of a file?Commands for displaying file contents (pg, more, page, and cat commands) The pg, more, and page commands allow you to view the contents of a file and control the speed at which your files are displayed. You can also use the cat command to display the contents of one or more files on your screen.
What command can you use to search for the word fruit in the text files in the above directory in Linux?grep fruit apple. txt chocholate. txt orange. txt; You can use the grep command to search files for certain words.
When using WC you Cannot specify all three options in the command line at the same time?When using wc, you cannot specify all three options (-l, -w and -c) in the command line at the same time. The pipe operator can connect several commands on the same command line.
|