Python Forum
best way to build as string from pieces
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
best way to build as string from pieces
#1
i'm building a string from pieces being appended. this does not fit into formatting or f-strings because they are maybe added according to an if conditional, repeated in a loop, and/or modified by function calls. i have been using a lot of += operators to do this. now i am wondering if it might be be better to .append() these strings to a list and ''.join() them all together at the end. a typical run in my current project will involve a few million += operations.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Shouldn't really make a difference when using a modern-ish python.
A few years ago, using += would result in quadratic complexity code, but nowadays python is smart enough to optimize this use case.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failed tkinter Compile In Custom 3.7.2 Build Using Custom Tcl/Tk Build gwc 0 2,563 Jan-25-2019, 01:56 PM
Last Post: gwc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020