question 154 Collections & Itertools · easy
Answers posted too fast
A spam filter flags a user who posts two answers within a short time of each other. Write has_burst(posts, gap): return True if any two posts by the same user were made less than gap seconds apart, otherwise False. The posts are not in time order.
Function
has_burst(posts, gap)postsa list of dictionaries with
owner and posted (a time in seconds)Returns
True or FalseRulesexactly
gap seconds apart is fine; posts by different users never count; the earlier post may come later in the listExamples
callhas_burst([{'owner': 'maya-k', 'posted': 1000}, {'owner': 'devon-r', 'posted': 1030}, {'owner': 'maya-k', 'posted': 1200}, {'owner': 'devon-r', 'posted': 1075}], 60)returnsTrue
callhas_burst([{'owner': 'maya-k', 'posted': 1000}, {'owner': 'devon-r', 'posted': 1030}, {'owner': 'maya-k', 'posted': 1200}, {'owner': 'devon-r', 'posted': 1075}], 30)returnsFalse
callhas_burst([{'owner': 'lena-o', 'posted': 50}], 600)returnsFalse