The ps examples in your question don't really give you the information you're asking about: the first lists all the processes on your system, not just those spawned by a particular program, and similarly the second lists the number of threads in every process.
If you want to find information about threads spawned by a particular process, you can look in /proc under /proc/<pid>/task. For example, here is a process with a single thread:
bash-4.4$ ls /proc/15355/task/
15355
And here's one that has three threads (in addition to the main thread):
bash-4.4$ ls /proc/15295/task/
15295 15296 15297 15298
The corresponding ps -L output for that process looks like:
bash-4.4$ ps -L -p 15295
PID LWP TTY TIME CMD
15295 15295 pts/4 00:00:00 python
15295 15296 pts/4 00:00:00 python
15295 15297 pts/4 00:00:00 python
15295 15298 pts/4 00:00:00 python
Getting the number of running processes from /proc takes a little more work, since Linux only maintains information about a process' parent, rather than it's children. That means you would need to scan through /proc and find every process for which the parent is your target process...and then repeat recursively for each of those processes.
You can use something like pstree to get this information, of course, but that output isn't really designed to be machine parseable.
popen()?proc/self/egls /proc/self/task -lLshows the 1 thread ls has launched.