kopia lustrzana https://github.com/peterhinch/micropython-font-to-py
Improve string reverse example.
rodzic
ac929fd1ce
commit
01949e4cdf
|
@ -18,10 +18,9 @@ def reverse(s):
|
||||||
or
|
or
|
||||||
```py
|
```py
|
||||||
def reverse(s):
|
def reverse(s):
|
||||||
if (l := len(s)) == 1:
|
if not (l := len(s) // 2):
|
||||||
return s
|
return s
|
||||||
l1 = l // 2
|
return ''.join((reverse(s[l:]), reverse(s[:l])))
|
||||||
return ''.join((rev(s[l1:]), rev(s[:l1])))
|
|
||||||
```
|
```
|
||||||
which aims to minimise the number of string creations.
|
which aims to minimise the number of string creations.
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue