<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: samueldavidwinter</title>
    <description>The latest articles on DEV Community by samueldavidwinter (@samueldavidwinter).</description>
    <link>https://dev.to/samueldavidwinter</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F463625%2Fe0061b41-2a09-44e0-8be3-d0bba75bc9db.jpeg</url>
      <title>DEV Community: samueldavidwinter</title>
      <link>https://dev.to/samueldavidwinter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samueldavidwinter"/>
    <language>en</language>
    <item>
      <title>Extracting a list of tuples from a list of dictionaries, some values separated with commas and single quotes and some without</title>
      <dc:creator>samueldavidwinter</dc:creator>
      <pubDate>Fri, 04 Sep 2020 17:58:46 +0000</pubDate>
      <link>https://dev.to/samueldavidwinter/extracting-a-list-of-tuples-from-a-list-of-dictionaries-some-values-separated-with-commas-and-single-quotes-and-some-without-2gem</link>
      <guid>https://dev.to/samueldavidwinter/extracting-a-list-of-tuples-from-a-list-of-dictionaries-some-values-separated-with-commas-and-single-quotes-and-some-without-2gem</guid>
      <description>&lt;p&gt;I have a list of dictionaries, each dictionary contains:&lt;/p&gt;

&lt;p&gt;First name&lt;br&gt;
Middle name&lt;br&gt;
Last name&lt;br&gt;
Title&lt;br&gt;
Address&lt;br&gt;
Email address&lt;br&gt;
Loyalty program For one client. Some of this information may be missing&lt;br&gt;
segment = [{'first-name': 'Elsa', 'last-name': 'Frost', 'title': 'Princess', 'address': '33 Castle Street, London', 'loyalty-program': 'Gold'}, {'first-name': 'Anna', 'last-name': 'Frost', 'title': 'Princess', 'loyalty-program': 'Platinum'}, {'first-name': 'Harry', 'middle-name': 'Harold', 'last-name': 'Hare', 'title': 'Mr', 'email-address': '&lt;a href="mailto:harry.harold@hare.name"&gt;harry.harold@hare.name&lt;/a&gt;', 'loyalty-program': 'Silver'}]&lt;br&gt;
For clients who have a physical address, I need to extract a list of tuples. Each tuple represents one client and contains their title, first name, middle name, and last name in that order if defined, and the mailing address.&lt;/p&gt;

&lt;p&gt;My code appears to be working.&lt;/p&gt;

&lt;p&gt;However, within each tuple, there needs to be single quotation marks around the whole and not individual parts of a clients name. There also needs to be quotation marks around the address. A comma needs to separate the address and the full name.&lt;/p&gt;

&lt;p&gt;('Princess Elsa Frost', '33 Castle Street, London')&lt;br&gt;
My code is returning the right information, but the elements of a patients name are separated by commas and single quotation marks&lt;/p&gt;

&lt;p&gt;def process_clients(segment):&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Creating a list to contain tuples with client full name and mailing address. 
updated = []
#Interacting through each dictionary, which represents each client
for dic in segment:
    newclient=[]
#Adding clients with a mailing address
    try:
        add = dic["address"]
    except:
        continue
#Adding, in order, the "title", "first-name", "middle-name", "last-name" and "address" of each client
    for data in ["title", "first-name", "middle-name", "last-name", "address"]:
        try:
            value = dic[data]
            newclient.append(value)
#If "title", "first-name", "middle-name" or "last-name" is not present in a clients data, no action is taken
        except:
            pass
#Additing the tuples with extracted client data to the created list        
    updated.append(tuple(newclient))
return updated
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;process_clients(segment)&lt;/p&gt;

&lt;p&gt;[('Princess',' Elsa ',' Frost ', '33 Castle Street, London')]&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
