1.1 --- a/lib/__builtins__/str.py Wed Dec 07 17:15:12 2016 +0100
1.2 +++ b/lib/__builtins__/str.py Wed Dec 07 17:24:39 2016 +0100
1.3 @@ -139,7 +139,30 @@
1.4 def endswith(self, s): pass
1.5 def find(self, sub, start=None, end=None): pass
1.6 def index(self, sub, start=None, end=None): pass
1.7 - def join(self, l): pass
1.8 +
1.9 + def join(self, l):
1.10 +
1.11 + "Join the elements in 'l' with this string."
1.12 +
1.13 + # Empty strings just cause the list elements to be concatenated.
1.14 +
1.15 + if not self.__bool__():
1.16 + return str(buffer(l))
1.17 +
1.18 + # Non-empty strings join the elements together in a buffer.
1.19 +
1.20 + b = buffer()
1.21 + first = True
1.22 +
1.23 + for s in l:
1.24 + if first:
1.25 + first = False
1.26 + else:
1.27 + b.append(self)
1.28 + b.append(s)
1.29 +
1.30 + return str(b)
1.31 +
1.32 def lower(self): pass
1.33 def lstrip(self, chars=None): pass
1.34 def replace(self, old, new, count=None): pass
2.1 --- a/tests/string.py Wed Dec 07 17:15:12 2016 +0100
2.2 +++ b/tests/string.py Wed Dec 07 17:24:39 2016 +0100
2.3 @@ -21,4 +21,14 @@
2.4 except ValueError, exc:
2.5 print "ord(s): value is not appropriate", exc.value
2.6
2.7 +l = ["Hello", "world!"]
2.8 +s3 = " ".join(l)
2.9 +print s3 # Hello world!
2.10 +
2.11 +s4 = "".join(l)
2.12 +print s4 # Helloworld!
2.13 +
2.14 print hash(s)
2.15 +print hash(s2)
2.16 +print hash(s3)
2.17 +print hash(s4)