Select all the last vertices of every branch
Select verts with only one linked edge

import bpy
import bmesh

context = bpy.context

ob = context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)
for v in bm.verts:
    v.select = len(v.link_edges) == 1

bmesh.update_edit_mesh(me)