News for hackers. Stuff that matters.
Re:Python Lists vs. Tuples by nerdponx on Friday August 19, 2016 @09:45PM (#12324662)
I use them as the semantic guide when I write code.

Then again, I also use single and double quotes as a semantic guide to mean different things. I feel like that would probably make most programmers want to throw the computer at the wall, but so it goes

Re:Python Lists vs. Tuples by colanderman on Friday August 19, 2016 @09:52PM (#12324692)
I do the same! But I get frustrated that I can neither modify individual elements of my "cultural" tuples, nor is there an immutable (functional) "cultural" list (or dictionary, for that matter).
Re:Python Lists vs. Tuples by philipov on Friday August 19, 2016 @09:51PM (#12324691)
what, of course, single quotes are for characters and double quotes are for strings.
Re:Python Lists vs. Tuples by markrages on Friday August 19, 2016 @10:28PM (#12324836)
C programmer identified.
Re:Python Lists vs. Tuples by omaranto on Friday August 19, 2016 @10:14PM (#12324765)
What do you use single and double quotes for?
Re:Python Lists vs. Tuples by SpaceManiac on Friday August 19, 2016 @10:25PM (#12324818)
I can't speak for GP, but I like to use single quotes for symbolic strings ('go_left', 'parent', 'alpha-campus', some_map['fixed_key']) and double quotes for textual strings ("An error occurred", "package/__main__.py").
Re:Python Lists vs. Tuples by BerislavLopac on Saturday August 20, 2016 @07:30AM (#12326091)
Sometimes this convention falls apart, e.g. when constructing HTML tags it is easier (and more readable) to write:

    return '<a href="{}">{}</a>'.format(url, text)
than

    return "<a href=\"{}\">{}</a>".format(url, text)
Especially for a lazy developer like me... :)
Re:Python Lists vs. Tuples by gsnedders on Saturday August 20, 2016 @04:28PM (#12328178)
Why not just use single-quotes in the HTML?
Re:Python Lists vs. Tuples by nerdponx on Monday August 22, 2016 @01:06PM (#12337730)
Fair. But I would consider those to be unformatted text, not symbols.
Re:Python Lists vs. Tuples by omaranto on Friday August 19, 2016 @10:31PM (#12324846)
Oh, I like that idea: compensate via a convention for Python's lack of a symbol data type. :)
Re:Python Lists vs. Tuples by jholman on Saturday August 20, 2016 @12:35AM (#12325230)
If you mean Ruby's symbols, Python has a data type with that set of properties. It's called 'str'.

If you want the behaviour of Ruby strings, you might use a `bytes` or `bytearray` type, or you might use a list of chars.

Re:Python Lists vs. Tuples by omaranto on Saturday August 20, 2016 @01:50AM (#12325397)
I thought Ruby ensured there was only one symbol with given contents, so that equality testing for symbols reduces to pointer equality. I don't Python strings behave that way.

But at any rate I wasn't thinking of performance characteristics but rather the stereotypical uses of symbols vs strings in languages that have both, so you are right that one can use Python strings in place of symbols, as SpaceManiac already pointed out above.

Re:Python Lists vs. Tuples by BerislavLopac on Saturday August 20, 2016 @07:26AM (#12326078)
> I thought Ruby ensured there was only one symbol with given contents, so that equality testing for symbols reduces to pointer equality. I don't Python strings behave that way.

In Python, string literals are reused, if that is what you meant.

    >>> a = 'abc'
    >>> b = 'abc'
    >>> a is b
    True
Re:Python Lists vs. Tuples by gsnedders on Saturday August 20, 2016 @04:29PM (#12328185)
This isn't guaranteed by the language, even if CPython does it. What is guaranteed is intern('abc') is intern('abc').
Re:Python Lists vs. Tuples by infinite8s on Saturday August 20, 2016 @11:15AM (#12326937)
String literals up to a certain size are reused.
Re:Python Lists vs. Tuples by omaranto on Saturday August 20, 2016 @02:06PM (#12327659)
Oh, cool, I didn't know that. I think in Ruby all symbols are reused, whether they are literals or constructed programatically. (Unlike Common Lisp symbols which can also de 'uninterned' if they are not literals.)
Re:Python Lists vs. Tuples by nerdponx on Saturday August 20, 2016 @12:44AM (#12325261)
Yup I do the same.

some_dict = {'key': "value"}