Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
forming a str one by one
#1
some complicated code needs to form a str one character at a time, as it figures out each character, one at a time. these characters can be any Unicode character, so inserting or appending bytearray is not an option. maybe forming a list is an option. but, i need to end up with a str type result. appending to a growing str type is not an option since str is immutable. i could reconstruct a new str each time like newstr = oldstr + character, but that would be a lot of work. or would it? is there a better way to build a str one character at a time?
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
a list and pass it to ''.join() when you need the str?
what produce/yield the individual chars that will form the str? can it be a generator that you can pass to ''.join(), removing the need for intermediate list?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
it probably is possible to make it be a generator. that sounds like a very good idea.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best way of taking a date prefix from a line and forming a file path from it? Skaperen 5 2,923 Jul-22-2019, 11:50 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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