What do ellipsis […] mean in a list?

前端 未结 5 1505
甜味超标
甜味超标 2020-11-22 10:46

I was playing around in python. I used the following code in IDLE:

p  = [1, 2]
p[1:1] = [p]
print p

The output was:

[1, [.         


        
5条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 11:16

    To the question "What's its use", here is a concrete example.

    Graph reduction is an evaluation strategy sometime used in order to interpret a computer language. This is a common strategy for lazy evaluation, notably of functional languages.

    The starting point is to build a graph representing the sequence of "steps" the program will take. Depending on the control structures used in that program, this might lead to a cyclic graph (because the program contains some kind of "forever" loop -- or use recursion whose "depth" will be known at evaluation time, but not at graph-creation time)...

    In order to represent such graph, you need infinite "data structures" (sometime called recursive data structures), like the one you noticed. Usually, a little bit more complex though.

    If you are interested in that topic, here is (among many others) a lecture on that subject:
    http://undergraduate.csse.uwa.edu.au/units/CITS3211/lectureNotes/14.pdf

提交回复
热议问题