3 ms·
Ruby is nicer to read than Python. Here's how each language reverses a string: # Ruby string.reverse() # Python string[::-1] Which looks better? Edit: I'm
by 16s 16y ago
Ruby is nicer to read than Python. Here's how each language reverses a string:
# Ruby
string.reverse()
# Python
string[::-1]
Which looks better?
Edit: I'm not sure why this is being down voted. It's a true statement.
Edit2: With all the down voting on Hacker News recently, I'm about to quit sharing my knowledge here. Maybe pg will do something about this. It needs to change otherwise good people will stop posting here.
Edit3:
irb(main):002:0> x = "hacker"
irb(main):003:0> puts x.reverse()
rekcah
>>> x = "hacker"
>>> print x[::-1]
rekcah
- anthonyb 16y agoI think possibly because it's 'fiddling around the edges'. Sure, it's nice to have a way to reverse a string, but you don't do that very often in practice - assigning to lists, calling functions, etc. are all far more common. But yeah, I hear you on the downvoting.
- deleted 16y ago[deleted]