To achieve the same functionality in Python, you can use the following code:
main.py186 chars7 lines
Explanation:
[]
instead of %w()
in Ruby.pop()
function is used to remove and return the element at the specified index from the array. In this case, we remove the element at index 2 using arr.pop(2)
.arr
after removing the element will give you ['blink', 'freakonomics']
.blink freakonomics
back into an array, we can use the split()
function. The ' '.join(arr)
part joins the elements of arr
with a space in between, and split()
splits the resulting string at each space, creating a list of words.Note: In Python, the array indices start from 0, so the element at index 2 is 'outliers' and not 'and'.
gistlibby LogSnag