Hacker News new | ask | show | jobs
by rahiel 3144 days ago
These two loops:

  raw_data = [line.split('|', 1) for line in [x.strip() for x in content]]
can be simplified to a single loop:

  raw_data = [line.strip().split('|', 1) for line in content]
Using str.replace here is also non-idiomatic:

  plt.title('Top $n Sites Visited'.replace('$n', str(topN)))
How about using str.format instead:

  plt.title('Top {n} Sites Visited'.format(n=topN))
2 comments

You could even use the new format strings from Python3.6.

  f"Top {topN} Sites Visited"
thanks! The code in my post is mainly more of a POC than anything else, but in my next post I’ll try to be more Pythonic.