home.social

#pythonsyntax — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #pythonsyntax, aggregated by home.social.

  1. ### Enclosed generator expressions in Python.

    x0 = [0, 1, 2]
    x1 = [x for x in x0]

    assert type(x0) == list
    assert type(x1) == list

    y0 = {0, 1, 2}
    y1 = {y for y in y0}

    assert type(y0) == set
    assert type(y1) == set

    z0 = (0, 1, 2)
    z1 = (z for z in z0)

    assert type(z0) == tuple
    assert type(z1) != tuple #Caveat programmator.

    ## Oh, did you mean:
    z2 = tuple(z for z in z0)
    assert type(z2) == tuple

    #ComputerProgramming
    #Python
    #PythonSyntax