3 ms·
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().sp
by rahiel 9y 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))
- hultner 9y agoYou could even use the new format strings from Python3.6. f"Top {topN} Sites Visited"
- applecrazy 9y agothanks! 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.