0
0
Data Analysis Pythondata~10 mins

Tokenization basics in Data Analysis Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to split the sentence into words using the split method.

Data Analysis Python
sentence = "Data science is fun"
tokens = sentence.[1]()
Drag options to blanks, or click blank then click option'
Asplit
Bstrip
Creplace
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using join instead of split
Using replace which changes characters
Using strip which removes spaces only at ends
2fill in blank
medium

Complete the code to tokenize the sentence by splitting on commas.

Data Analysis Python
sentence = "apple,banana,orange"
tokens = sentence.[1](",")
Drag options to blanks, or click blank then click option'
Areplace
Bsplit
Cstrip
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using strip which removes characters only at ends
Using replace which changes characters but does not split
Using join which combines strings
3fill in blank
hard

Fix the error in the code to tokenize the sentence into words.

Data Analysis Python
sentence = "Hello world"
tokens = sentence.[1](" ")
Drag options to blanks, or click blank then click option'
Asplit
Bjoin
Creplace
Dstrip
Attempts:
3 left
💡 Hint
Common Mistakes
Using join which combines strings
Using replace which changes characters
Using strip which removes spaces only at ends
4fill in blank
hard

Complete the code to create a dictionary with words as keys and their lengths as values.

Data Analysis Python
words = ['data', 'science', 'fun']
lengths = {word: [1] for word in words}
Drag options to blanks, or click blank then click option'
A:
Blen(word)
Cword
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' in dictionary comprehension
Using the word itself as value instead of its length
5fill in blank
hard

Fill all three blanks to create a dictionary of words and their lengths, including only words longer than 3 letters.

Data Analysis Python
words = ['data', 'is', 'fun', 'science']
lengths = { [1] : [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Clen(word) > 3
Dword.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.upper() as key which changes the word
Not filtering words by length
Using '=' instead of ':' in dictionary comprehension