Python Forum
[nested dics] Easy way to find if a key exists?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[nested dics] Easy way to find if a key exists?
#7
For some reason, it finds 'Placemark', but not 'LineString', altough both are nested dictionaries:

print(key_exists2(doc, 'Placemark'))
#True
print(key_exists2(doc, 'LineString'))
#False
input.kml:
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Document.kml</name>
    <open>1</open>
    <Style id="exampleStyleDocument">
      <LabelStyle>
        <color>ff0000cc</color>
      </LabelStyle>
    </Style>
    <Placemark>
      <name>Document Feature 1</name>
      <styleUrl>#exampleStyleDocument</styleUrl>
      <Point>
        <coordinates>-122.371,37.816,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Document Feature 2</name>
      <styleUrl>#exampleStyleDocument</styleUrl>
      <Point>
        <coordinates>-122.370,37.817,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>My track</name>
      <LineString>
        <coordinates>-0.376291,43.296237,199.75
        -0.377381,43.29405</coordinates>
      </LineString>
    </Placemark>
  </Document>
</kml>
Reply


Messages In This Thread
RE: [nested dics] Easy way to find if a key exists? - by Winfried - Sep-17-2020, 03:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [Beautifulsoup] Find if element exists, and edit/append? Winfried 2 4,537 Sep-03-2022, 10:14 PM
Last Post: Winfried
  Python Program to Find the Total Sum of a Nested List vlearner 8 5,181 Jan-23-2022, 07:20 PM
Last Post: menator01
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 2,216 May-27-2020, 08:34 AM
Last Post: DeaD_EyE
  Easy way to sort a nested dict Alfalfa 3 5,733 Dec-07-2018, 04:12 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020