3 ms·
I know the reasons why and how mutating methods work in Python. Nevertheless I find this here much more elegant: data.sort.tail.first # or this data.append(7
by submeta 9y ago
I know the reasons why and how mutating methods work in Python.
Nevertheless I find this here much more elegant:
data.sort.tail.first # or this
data.append(7).append(3)
More elegant than this:
sorted(data)[1:][0]
data.append(7) # and then
data.append(3)
I love method chaining in Elixir or Javascript. In Python I have to create temp variables here and there to capture / further process intermediate results.
Having said that: Python has it's strengths. I use it more than any other programming language.
- xapata 9y agoI understand the preference and the difficulty created by methods and operators that are essentially statements instead of expressions. However, when making that criticism we should also acknowledge the benefit of requiring or encouraging multiple lines for those actions. if (x=42) {} Has burned many people. Append having a useful return is comparable, though probably not as much of a trap. > sorted(data)[1:][0] I don't want to get into the weeds, but shouldn't that just be sorted(data)[1] Or if you like unpacking for clarity first, second = sorted(data)[:2] ?