Posts: 4,558
Threads: 1,463
Joined: Sep 2016
which is better?
0.
if s[0] == "'" and s[-1] == "'":
1.
if (s[0],s[-1]) == ("'","'"):
2.
if (s[0]+s[-1]) == "''":
or any other suggestions?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,558
Threads: 1,463
Joined: Sep 2016
Aug-08-2017, 06:06 AM
(This post was last modified: Aug-08-2017, 06:06 AM by Skaperen.)
(Aug-08-2017, 01:28 AM)ichabod801 Wrote: I would say the first one is the most readable code of the three. I would also consider a regular expression or:
if s.startswith("'") and s.endswith("'")
i'm going to be removing the quotes. anything better than:
if s.startswith("'") and s.endswith("'"):
s = s[1:-1]
?
FYI, s comes from repr() which will have the quotes if a string is given to it, but those will be awkward for the usage, which is to be part of a filename.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,558
Threads: 1,463
Joined: Sep 2016
if there are quotes in the middle, i want to keep them. i'm removing the quotes that repr() adds to a string, but it might have not been a string. i should make some variant code for unicode (v2), bytes (v3), and bytearray.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.