Skip to content

Deprecate dict comprehension construction in favor for Generator #16510

Closed
@dhoegh

Description

As the new Generator syntax matches nicely with the construction of dictionaries. I propose using generators instead of using the comprehensions syntax to construct dictionaries as the generator syntax is closer to the syntax for manually initialization of the dictionaries. This should be deprecated:

julia> [i=>i*2 for i=1:2]
Dict{Int64,Int64} with 2 entries:
  2 => 4
  1 => 2

In favor for:

julia> Dict(i=>i*2 for i=1:2)
Dict{Int64,Int64} with 2 entries:
  2 => 4
  1 => 2

The deprecation will match the deprecation in:

julia> [1=>2, 2=>4]

WARNING: deprecated syntax "[a=>b, ...]" at REPL[53]:1.
Use "Dict(a=>b, ...)" instead.
Dict{Int64,Int64} with 2 entries:
  2 => 4
  1 => 2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions