title: Python None value not applied
body: <p>I'm trying to look for keys and values in an AWS instance. If the key is present I want the script to report the value if it exists or report <code>None</code> if the key has no value.</p>
  
  <p>I do this for a number of key value pairs and they all work except one.</p>
  
  <p>These key/value pairs report <code>None</code> if there is no value for the key:</p>
  
  <pre><code>instance_list = ec2.describe_instances()
      for reservation in instance_list["Reservations"]:
          for instance in reservation.get("Instances", []):
              if instance['PublicDnsName']:
                  public_dns_name = instance['PublicDnsName']
              else:
                  public_dns_name = None
              if 'KeyName' in instance:
                  key_name = instance['KeyName']
              else:
                  key_name = None
  </code></pre>
  
  <p>This one always shows a blank value instead of <code>None</code>. It does report a value when they key has a value:</p>
  
  <pre><code>                if 'PrivateDnsName' in instance:
                      private_dns = instance['PrivateDnsName']
                  else:
                      private_dns = None
  </code></pre>
  
  <p>Here is the value of <code>instance</code> for an instance ID that shows a blank entry for <code>private_dns</code>:</p>
  
  <pre><code>{'AmiLaunchIndex': 0, 'ImageId': 'ami-062f7200baf2fa504', 'InstanceId': 'i-02fa5c552a10ddfca', 'InstanceType': 't2.micro', 'KeyName': 'sncr-timd', 'LaunchTime': datetime.datetime(2020, 1, 14, 22, 25, tzinfo=tzutc()), 'Monitoring': {'State': 'disabled'}, 'Placement': {'AvailabilityZone': 'us-east-1b', 'GroupName': '', 'Tenancy': 'default'}, 'PrivateDnsName': '', 'ProductCodes': [], 'PublicDnsName': '', 'State': {'Code': 48, 'Name': 'terminated'}, 'StateTransitionReason': 'User initiated (2020-01-15 14:43:16 GMT)', 'Architecture': 'x86_64', 'BlockDeviceMappings': [], 'ClientToken': '', 'EbsOptimized': False, 'EnaSupport': True, 'Hypervisor': 'xen', 'NetworkInterfaces': [], 'RootDeviceName': '/dev/xvda', 'RootDeviceType': 'ebs', 'SecurityGroups': [], 'StateReason': {'Code': 'Client.UserInitiatedShutdown', 'Message': 'Client.UserInitiatedShutdown: User initiated shutdown'}, 'VirtualizationType': 'hvm', 'CpuOptions': {'CoreCount': 1, 'ThreadsPerCore': 1}, 'CapacityReservationSpecification': {'CapacityReservationPreference': 'open'}, 'HibernationOptions': {'Configured': False}, 'MetadataOptions': {'State': 'pending', 'HttpTokens': 'optional', 'HttpPutResponseHopLimit': 1, 'HttpEndpoint': 'enabled'}}
  </code></pre>
  
  <p>This is how the output looks when the <code>instance</code> does have a <code>private_dns</code> key and value:</p>
  
  <pre><code>Private DNS: ip-172-31-37-19.us-east-2.compute.internal
  </code></pre>
  
  <p>This is how an <code>instance</code> looks when <code>private_dns</code> exists:</p>
  
  <pre><code>{'AmiLaunchIndex': 0, 'ImageId': 'ami-02ccb28830b645a41', 'InstanceId': 'i-069e87e16db1bf49b', 'InstanceType': 't2.micro', 'KeyName': 'sncr-timd', 'LaunchTime': datetime.datetime(2020, 1, 14, 22, 27, 17, tzinfo=tzutc()), 'Monitoring': {'State': 'disabled'}, 'Placement': {'AvailabilityZone': 'us-east-2c', 'GroupName': '', 'Tenancy': 'default'}, 'PrivateDnsName': 'ip-172-31-37-19.us-east-2.compute.internal', 'PrivateIpAddress': '172.31.37.19', 'ProductCodes': [], 'PublicDnsName': 'ec2-18-223-15-106.us-east-2.compute.amazonaws.com', 'PublicIpAddress': '18.223.15.106', 'State': {'Code': 16, 'Name': 'running'}, 'StateTransitionReason': '', 'SubnetId': 'subnet-22038f6e', 'VpcId': 'vpc-859c5aee', 'Architecture': 'x86_64', 'BlockDeviceMappings': [{'DeviceName': '/dev/xvda', 'Ebs': {'AttachTime': datetime.datetime(2020, 1, 14, 22, 27, 18, tzinfo=tzutc()), 'DeleteOnTermination': True, 'Status': 'attached', 'VolumeId': 'vol-08f30292b9a7039bc'}}], 'ClientToken': '', 'EbsOptimized': False, 'EnaSupport': True, 'Hypervisor': 'xen', 'NetworkInterfaces': [{'Association': {'IpOwnerId': 'amazon', 'PublicDnsName': 'ec2-18-223-15-106.us-east-2.compute.amazonaws.com', 'PublicIp': '18.223.15.106'}, 'Attachment': {'AttachTime': datetime.datetime(2020, 1, 14, 22, 27, 17, tzinfo=tzutc()), 'AttachmentId': 'eni-attach-0937973380674deef', 'DeleteOnTermination': True, 'DeviceIndex': 0, 'Status': 'attached'}, 'Description': '', 'Groups': [{'GroupName': 'launch-wizard-1', 'GroupId': 'sg-08b8c8a89bcc3c692'}], 'Ipv6Addresses': [], 'MacAddress': '0a:d9:9b:03:a7:a8', 'NetworkInterfaceId': 'eni-0bfcd12253ecf87ec', 'OwnerId': '565241749827', 'PrivateDnsName': 'ip-172-31-37-19.us-east-2.compute.internal', 'PrivateIpAddress': '172.31.37.19', 'PrivateIpAddresses': [{'Association': {'IpOwnerId': 'amazon', 'PublicDnsName': 'ec2-18-223-15-106.us-east-2.compute.amazonaws.com', 'PublicIp': '18.223.15.106'}, 'Primary': True, 'PrivateDnsName': 'ip-172-31-37-19.us-east-2.compute.internal', 'PrivateIpAddress': '172.31.37.19'}], 'SourceDestCheck': True, 'Status': 'in-use', 'SubnetId': 'subnet-22038f6e', 'VpcId': 'vpc-859c5aee', 'InterfaceType': 'interface'}], 'RootDeviceName': '/dev/xvda', 'RootDeviceType': 'ebs', 'SecurityGroups': [{'GroupName': 'launch-wizard-1', 'GroupId': 'sg-08b8c8a89bcc3c692'}], 'SourceDestCheck': True, 'VirtualizationType': 'hvm', 'CpuOptions': {'CoreCount': 1, 'ThreadsPerCore': 1}, 'CapacityReservationSpecification': {'CapacityReservationPreference': 'open'}, 'HibernationOptions': {'Configured': False}, 'MetadataOptions': {'State': 'applied', 'HttpTokens': 'optional', 'HttpPutResponseHopLimit': 1, 'HttpEndpoint': 'enabled'}}
  </code></pre>
  
  <p>I'm wondering why that is. How do I correct that?</p>