Collecting hashtags
Write code · Basic · §3.3 Working with strings
Complete the function solution, which returns a list of the hashtags in the post text text, in the order they appear.
A hashtag is a whole word that starts with # and is at least 2 characters long. Words are separated by a single space.
If the same hashtag appears more than once, include it only once, at the place where it first appears. Uppercase and lowercase letters are treated as different characters.
Function
solution(text)
Constraints
- The length of
textis from 1 to 1,000. textconsists of English letters, digits, #, and spaces. It does not start or end with a space, and there are never two or more spaces in a row.- A word that starts with # has no other # after the first character.
Examples
| text | result |
|---|---|
'today #python study #AI #python' | ['#python', '#AI'] |
'a post with no hashtags' | [] |
Starter code
def solution(text):
answer = []
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.