9 Answers
+ 6
python: standard library, exception handling
ruby: case statements, unless statements
+ 5
Hmm.. Seems about right, thanks :D
+ 5
There are a number of other useful methods available for manipulating arrays.
Here are some of the most used ones:
array.length or array.size returns the number of elements in array.
array.sort returns a new array with the elements sorted
array.uniq returns a new array with duplicate values removed from array.
array.uniq! removes duplicates in place.
array.freeze safeguards the array, preventing it from being modified.
array.include?(obj) returns true if obj is present in array, false otherwise.
array.min returns the element with the minimum value.
array.max returns the element with the maximum value.
this text, copied from Ruby course > Collections > Array manipulations, includes some built-in array functions in ruby that aren't in python. but you can rebuild most:
array.length - len(list)
array.include?(x) - if x in list:
array.min - min(list)
array.max - max(list)
probably more, but too lazy now
+ 5
another thing in ruby that python doesnt have are in-place operators, for example:
array.reverse!
would be done in python using
list = list[::-1]
as you see, list is reassigned, array isnt.
but, as The Zen of Python states:
Explicit is better than implicit.
edit: There is actually the in-place method list.reverse()...
+ 5
also, ruby has some additional loops:
arr.each do - for i in list:
loop do - while True:
x.times do - for i in range(x):
+ 5
python, on the other hand, has explicit type conversion. until now, i have no idea what the ruby equivalents of
str(x), float(x), bool(x), list(x), dict(x), tuple(x) etc
are.
ruby has the .to_s(x) method, that helps with easy conversion between numeric systems
+ 5
btw if youre wondering im going through the ruby course and posting everything i notice here
+ 4
I also think you can't operate with arrays in python as much as it lets you in ruby.
+ 4
@JRE I've noticed that too I forgot what it is but I know that you cant do something in Python but you can in Rubu