java and python equivalent of php's foreach($array as $key => $value)

前端 未结 8 972
抹茶落季
抹茶落季 2020-12-20 11:56

In php, one can handle a list of state names and their abbreviations with an associative array like this:



        
相关标签:
8条回答
  • 2020-12-20 12:45

    TreeMap is not an answer to your question because it sorts elements by key, while LinkedHashMap preserves original order. However, TreeMap is more suitable for the dictionary because of sorting.

    0 讨论(0)
  • 2020-12-20 12:49

    Also, to maintain insertion order, you can use a LinkedHashMap instead of a HashMap.

    0 讨论(0)
提交回复
热议问题