If Python has an implementation of Ruby's next
method? I mean something what works exactly the same as in Ruby, so if I type e.g. "z".next
it will return "aa"
(instead of just next sign in ascii table), "az".next
will return "ba"
and so on.
Asked
Active
Viewed 173 times
-1

Tkin2ter
- 11
- 2
-
I assume you mean `"z".next` and `"az".next`. – user94559 Jul 27 '16 at 17:52
-
No, python doesn't have this. You'd need to build it yourself... – mgilson Jul 27 '16 at 17:52
-
Generally speaking, if you ask for the exact same functionality from another language (when it's not common among many languages like functions/methods or loops), it means that you're not adopting the mindset of the language. You should step back and ask the question, "What am I trying to accomplish at a higher level?" Python may have different idiomatic ways of doing *that*. – jpmc26 Jul 27 '16 at 17:56
-
This seems like a simple base-26 increment. – erip Jul 27 '16 at 17:57
-
@erip That's what I thought at first, but I don't think it is. I would think that in base 26, `a == 0`, `b == 1`, etc., and after `z == 25`, the next number would be `ba == 26` (not `aa`, which would be the same as `a`). – user94559 Jul 27 '16 at 18:04
-
@smarx Ah, excellent observation! – erip Jul 27 '16 at 18:57
1 Answers
0
I don't believe there is a built-in method for this in Python. A similar question was asked on How can I get the next string, in alphanumeric ordering, in Python? and the accepted answer gives a solution.