DEV Community

loading...

Day 92 Of 100DaysOfCode: Charting Practice

iamdurga profile image Durga Pokharel ・1 min read

Today is my 92th day of #100daysofcode and #python learning journey. Today also keep learning from DataCamp completed some assignments here. Studied some articles from dev. Following code for charting using matplotlib and tokenization.

Code

# Split the script into lines: lines
lines = holy_grail.split('\n')

# Replace all script lines for speaker
pattern = "[A-Z]{2,}(\s)?(#\d)?([A-Z]{2,})?:"
lines = [re.sub(pattern, '', l) for l in lines]

# Tokenize each line: tokenized_lines
tokenized_lines = [regexp_tokenize(s, "\w+") for s in lines]

# Make a frequency list of lengths: line_num_words
line_num_words = [len(t_line) for t_line in tokenized_lines]

# Plot a histogram of the line lengths
plt.hist(line_num_words)

# Show the plot
plt.show()
Enter fullscreen mode Exit fullscreen mode

Discussion (1)

pic
Editor guide
Collapse
otumianempire profile image
Otu Michael

Well done. Just 8 days more. I hope you'd share your experience and tips, do's and dont's.