Thanks for pointing to code.
I just learned how to copy&paste pep8online.com validated function definition with
webrepl_client.py in raw mode:
Code: Select all
$ python3 webrepl_client.py 192.168.4.1
Password: abcd
WebREPL connected
>>> rev
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rev' is not defined
>>> \x01
raw REPL; CTRL-B to exit
>def rev(s):
r = ""
for c in s:
r = c+r
return r
\x04
OK>\x02
MicroPython v1.9.4-481-g3cd2c281d on 2018-09-04; ESP module with ESP8266
Type "help()" for more information.
>>>
>>> exit
### closed ###
$
[::-1] can be done alternatively by rev() just defined:
Code: Select all
$ python3 webrepl_client.py 192.168.4.1
Password: abcd
WebREPL connected
>>> rev("hello")
'olleh'
>>>
P.S:
Not sure whether recursive rev() is better or not, works the same in MicroPython:
Code: Select all
def rev(s):
return "" if not(s) else rev(s[1::])+s[0]