Here's the assignment given:
Using the file school_prompt.txt, if the character ‘p’ is in a word, then add the word to a list called p_words. (I will post text file at bottom of this post.)
Here's my attempt:
If interested in school_prompt.txt, see below.
Writing essays for school can be difficult but
many students find that by researching their topic that they
have more to say and are better informed. Here are the university
we require many undergraduate students to take a first year writing requirement
so that they can
have a solid foundation for their writing skills. This comes
in handy for many students.
Different schools have different requirements, but everyone uses
writing at some point in their academic career, be it essays, research papers,
technical write ups, or scripts.
I bolded the 'p' words.
Using the file school_prompt.txt, if the character ‘p’ is in a word, then add the word to a list called p_words. (I will post text file at bottom of this post.)
Here's my attempt:
write = open("school_prompt.txt", "r") p_words = [] for aline in write: items = aline.split() if "p" in items: p_words.append(items) print(p_words) write.close()
Output:My result: []
Expected result: ['topic', 'point', 'papers', 'ups', 'scripts']
I'm not sure where I went wrong, but it feels like I'm only getting the first line of text (no 'p' in first line).If interested in school_prompt.txt, see below.
Writing essays for school can be difficult but
many students find that by researching their topic that they
have more to say and are better informed. Here are the university
we require many undergraduate students to take a first year writing requirement
so that they can
have a solid foundation for their writing skills. This comes
in handy for many students.
Different schools have different requirements, but everyone uses
writing at some point in their academic career, be it essays, research papers,
technical write ups, or scripts.
I bolded the 'p' words.