<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Dictionaries on Script Everything</title>
    <link>https://scripteverything.com/tags/dictionaries/</link>
    <description>Recent content in Dictionaries on Script Everything</description>
    <generator>Hugo -- 0.146.0</generator>
    <language>en-au</language>
    <lastBuildDate>Sat, 20 Jan 2024 23:14:40 +0000</lastBuildDate>
    <atom:link href="https://scripteverything.com/tags/dictionaries/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Read A CSV File To List Of Dictionaries In Python</title>
      <link>https://scripteverything.com/read-a-csv-file-to-list-of-dictionaries-in-python/</link>
      <pubDate>Sat, 20 Jan 2024 23:14:40 +0000</pubDate>
      <guid>https://scripteverything.com/read-a-csv-file-to-list-of-dictionaries-in-python/</guid>
      <description>&lt;p&gt;The most common form of data I have played with is generally found in CSV format. This makes the data easy to understand but difficult to modify or change, especially when the CSV file contains lots of columns.&lt;/p&gt;
&lt;p&gt;In this article I will demonstrate how I frequently use this file format to import it into a useable data structure in Python, namely, a list of Python dictionaries.&lt;/p&gt;
&lt;p&gt;Let’s start with defining the basic terminology so we’re on the same page before jumping into some examples.&lt;/p&gt;</description>
    </item>
    <item>
      <title>What Does Asterisk Before Variable Mean In Python?</title>
      <link>https://scripteverything.com/what-does-asterisk-before-variable-name-mean-in-python/</link>
      <pubDate>Sat, 12 Mar 2022 22:21:04 +0000</pubDate>
      <guid>https://scripteverything.com/what-does-asterisk-before-variable-name-mean-in-python/</guid>
      <description>&lt;p&gt;What does the asterisk before a variable name mean in Python? For example, if I have a variable that contains a list of strings and the name of the variable is called &lt;code&gt;my_list&lt;/code&gt; what does &lt;code&gt;*my_list&lt;/code&gt; do?&lt;/p&gt;
&lt;p&gt;The asterisk is an operator in Python that is commonly known as the multiplication symbol when used between two numbers (&lt;code&gt;2 * 3&lt;/code&gt; will produce &lt;code&gt;6&lt;/code&gt;) but when it is inserted at the beginning of a variable, such as an iterable, like a list or dictionary, it expands the contents of that variable.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Python Initialize Dictionary: Use Dict Constructor Or Dict Literal?</title>
      <link>https://scripteverything.com/how-to-initialize-a-dictionary-in-python/</link>
      <pubDate>Thu, 10 Mar 2022 10:36:56 +0000</pubDate>
      <guid>https://scripteverything.com/how-to-initialize-a-dictionary-in-python/</guid>
      <description>&lt;p&gt;How do you initialize an empty dictionary in Python? Is it best to use &lt;code&gt;dict()&lt;/code&gt; or &lt;code&gt;{}&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;There are two common ways of initializing a dictionary in Python. One involves using the built-in function &lt;code&gt;dict()&lt;/code&gt; and is known as the &lt;em&gt;dict constructor&lt;/em&gt;, whereas the other method is known as &lt;em&gt;dict literal&lt;/em&gt; and has the syntax &lt;code&gt;{}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here’s an example demonstrating how to initialize using both approaches in the Python REPL:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Sort Dict By Value Or Sort Dict By Key In Python: 1 Liners</title>
      <link>https://scripteverything.com/sort-dictionary-by-key-or-value-in-python/</link>
      <pubDate>Fri, 12 Nov 2021 14:11:35 +0000</pubDate>
      <guid>https://scripteverything.com/sort-dictionary-by-key-or-value-in-python/</guid>
      <description>&lt;p&gt;It can be easy to &lt;a href=&#34;https://scripteverything.com/reverse-order-of-list-python/&#34;&gt;sort a list&lt;/a&gt;, whether a list of strings or even a &lt;a href=&#34;https://scripteverything.com/sort-list-by-dict-values-python/&#34;&gt;list of dictionaries&lt;/a&gt;, but can you sort a dictionary?&lt;/p&gt;
&lt;p&gt;One way to sort a dictionary by the values of each &lt;code&gt;key : value&lt;/code&gt; pair in Python is to use a &lt;strong&gt;dictionary comprehension&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Dictionary comprehensions are very similar to &lt;a href=&#34;https://scripteverything.com/find-length-of-list-in-python/&#34;&gt;list comprehensions&lt;/a&gt; and have the following schema:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;new_dict&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;key&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;value&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;key&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;original_dict&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;items&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The first expression within the dictionary comprehension, the &lt;code&gt;key: value&lt;/code&gt; portion, is the basic structure for setting any key and value pair within a dictionary. The second expression is familiar as the &lt;a href=&#34;https://scripteverything.com/python-for-loop-one-liner/&#34;&gt;one-liner for loop&lt;/a&gt;, and within this statement we have a tuple representing the key and value returned from the dictionary’s &lt;code&gt;.items()&lt;/code&gt; method.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Enumerate Dictionary In Python: Video Demonstration</title>
      <link>https://scripteverything.com/enumerate-dictionary-in-python/</link>
      <pubDate>Tue, 09 Nov 2021 07:16:00 +0000</pubDate>
      <guid>https://scripteverything.com/enumerate-dictionary-in-python/</guid>
      <description>&lt;p&gt;Previously I looked at how to use the &lt;code&gt;enumerate()&lt;/code&gt; built-in function with a &lt;a href=&#34;https://scripteverything.com/how-to-use-2-variables-in-for-loop-in-python-code-examples/&#34;&gt;for loop to provide two variables when iterating through a list&lt;/a&gt;. In that article the &lt;code&gt;enumerate()&lt;/code&gt; function provides both an index number and the element in each list by wrapping these together into a tuple.&lt;/p&gt;
&lt;p&gt;But what happens when the &lt;code&gt;enumerate()&lt;/code&gt; function is applied to a dictionary?&lt;/p&gt;
&lt;p&gt;As done previously let’s inspect the output of the enumerated dictionary by printing its contents:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Create A Dictionary In Python: Quick 5 Minute Beginners Guide</title>
      <link>https://scripteverything.com/create-a-dictionary-in-python-quick-5-minute-beginners-guide/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://scripteverything.com/create-a-dictionary-in-python-quick-5-minute-beginners-guide/</guid>
      <description>&lt;p&gt;How do you create a dictionary in Python?&lt;/p&gt;
&lt;p&gt;Dictionaries in Python are mutable data types that contain &lt;code&gt;key: value&lt;/code&gt; pairs. A dictionary can be a great way to organise information, especially if checks need to be performed prior for uniqueness and/or the value of that key needs to be changed, skipped or inserted.&lt;/p&gt;
&lt;h2 id=&#34;creating-a-dictionary&#34;&gt;Creating A Dictionary&lt;/h2&gt;
&lt;p&gt;Dictionaries can be created using either the &lt;code&gt;dict()&lt;/code&gt; constructor method, using the &lt;code&gt;dict&lt;/code&gt; literal annotation &lt;code&gt;{}&lt;/code&gt; or using a &lt;code&gt;dict&lt;/code&gt; comprehension.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Sort Nested Dictionary By Key Or By Value In Python: One Liner</title>
      <link>https://scripteverything.com/sort-nested-dictionary-by-key-or-by-value-in-python-one-liner/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://scripteverything.com/sort-nested-dictionary-by-key-or-by-value-in-python-one-liner/</guid>
      <description>&lt;p&gt;How do you sort a nested dictionary in Python by key or by value?&lt;/p&gt;
&lt;p&gt;Throughout this article, I will use the following example, which displays a nested dictionary that contains three main properties labelled &lt;code&gt;dict1&lt;/code&gt;, &lt;code&gt;dict2&lt;/code&gt;, &lt;code&gt;dict3&lt;/code&gt; and from each key they reference another dictionary which contains a simple dictionary of three keys labelled &lt;code&gt;A&lt;/code&gt;, &lt;code&gt;B&lt;/code&gt; and &lt;code&gt;C&lt;/code&gt; with each key matched to the same value &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
