Hi! I'm a Computer Science / Data Science student from both the Federal University of Rio Grande do Sul (Brazil) and the INP Grenoble - Ensimag (France). Currently taking myself for a walk in the R...
The fact that, in Python, "joining an array using a given string" is phrased as "use this string to join an array".
# this does not work, sadly
['a','b','c'].join('-')# this works
'-'.join(['a','b','c'])
Now I'm used to it, but I used to get it wrong all the time, because 'join' is an active verb, so at least for me it makes sense to put it after the thing being joined.
It's because the argument to join can be anything that you can iterate over e.g. list, tuple, array etc. Python tends to make functions take duck-typed arguments rather than having interface-style compatibility on types.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The fact that, in Python, "joining an array using a given string" is phrased as "use this string to join an array".
Now I'm used to it, but I used to get it wrong all the time, because 'join' is an active verb, so at least for me it makes sense to put it after the thing being joined.
Yup, I get that wrong every time I attempt to join an array. Logically
join
should either be a part of the array type or a standalone function.I never understand why join is applying in separator passing the list to join them..
It's because the argument to
join
can be anything that you can iterate over e.g. list, tuple, array etc. Python tends to make functions take duck-typed arguments rather than having interface-style compatibility on types.