String concatenation with a for loop - Python Discussions
Nov 26, 2024 ... Hello everyone, 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: ...
Nov 26, 2024 ... Hello everyone, 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: ...
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 method, or even a sequence method, since we need to join arbitary iterables including sets, iterators and any other iterable object.
Jan 3, 2023 ... join() on a string literal. I remember ages ago when we were debating how to add a string join function, there were arguments to making it ...
Discussions related to the Python Programming Language, Python Community, and Python Software Foundation operations.Powered by Discourse, best viewed with JavaScript enabled.
Jan 23, 2020 ... I want to use str.join to directly construct multi-line strings, i.e.: "\n".join( "line1", "line2", ) but because only an iterable is ...
This is a standard question of finding the longest substring without repeating characters. My code does work, but I have two while loops of which I am not sure any one can be further simplified: class Solution: def lengthOfLongestSubstring(self, s: str) -> int
Feb 21, 2023 ... join() . The latter is a low level operation on arbitrary sequences/iterables, which are expected to provide string elements (not providing ...
Strings (like most Python “containers”) are true if not empty and false if empty. This means that all(e) will always return True. The usual way of doing what you’re doing is very close to what you have done: loop over secret_word_copy checking that all its characters appear in letters_guessed.
Jul 11, 2026 ... Have you tried moving "|".join(d) outside the loop or compiling the regex ahead of time ( re.compile )?. inventshah ( ...
Mar 16, 2022 ... So, you'd have \n\n.join(your_findall_output) , which will return a single string with all of the paragraph blocks separated by two line breaks, ...