String joining design - Page 3 - Python Discussions
Jan 2, 2023 ... You're joining strings with strings, using a string separator. Why are you surprised its a string method? It certainly shouldn't be just a list ...
Jan 2, 2023 ... You're joining strings with strings, using a string separator. Why are you surprised its a string method? It certainly shouldn't be just a list ...
Discussions on Python.org. String concatenation with a for loop.When I run this program on Python 3.12.6, debian trixie: # Part 1 def test(): s = 'a'*1_000_000 t = '' for c in s: print(len(t), id(t)).
timeit longest_unique_substring(string.ascii_lowercase) 11.6 µs ± 275 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each). Both of your methods take essentially the same time, since the nested loop doesn’t come into effect, while the simpler method above is nearly three times faster.
What you want is to call the .write() method with the string you want to write, i.e. f2.write(your_output_string_here). Furthermore, @soil was also correct in inferring that you need to pass a string to the .write() method, not a list of strings.