Python Forum
Syntactic sugar for explicit lists?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntactic sugar for explicit lists?
#4
(May-10-2018, 06:09 PM)ThiefOfTime Wrote: since strings always has to be inside of quotes i don't think that this is possible in python. Though, what comes close to that what you want to do is when you have a string some_string = "a b c d e f g h i j k l m n o p q r s t u v w x y z" and you then use the split operator
some_string = "a b c ... z"
list = some_string.strip()
then list == ["a", "b", ..., "z"]
But maybe someone else nows a different way :)

Please, never - even in examples - shadow builtin "list" with a custom variable

(May-10-2018, 05:44 PM)Antipaladin Wrote: When creating an explicit list, list = [ 'a', 'b', 'c', ... 'z' ], is there a way to "self quote" like @list = qw( a b c ... z) in Perl?

There are str and repr functions in python - for a "flat" list of scalars, their output is similar
Output:
In [1]: l = list('abcde') In [2]: l Out[2]: ['a', 'b', 'c', 'd', 'e'] In [3]: str(l) Out[3]: "['a', 'b', 'c', 'd', 'e']" In [4]: repr(l) Out[4]: "['a', 'b', 'c', 'd', 'e']"
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
RE: Syntactic sugar for explicit lists? - by volcano63 - May-10-2018, 07:10 PM
RE: Syntactic sugar for explicit lists? - by wavic - May-10-2018, 08:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Being explicit about the items inside a tuple argument rudihammad 3 2,500 Dec-04-2019, 08:10 AM
Last Post: perfringo
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,353 Mar-20-2019, 08:01 PM
Last Post: stillsen
  convert non-string with explicit base jacklee26 5 16,583 Nov-06-2018, 06:50 AM
Last Post: jacklee26
  Newb: Simple Explicit Formula Duplicitous 1 3,190 May-05-2017, 07:03 PM
Last Post: buran

Forum Jump:

User Panel Messages

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