Typically, Heap can be of two types:
- Max -Heap:In Max-Heap, the key present in the root node must be the largest among the keys present in all of its children. The same property must be recursively true for all subtrees in this binary tree.
- Min-Heap:In Min-Heap, the key present at the root node must be the smallest keys present in all of its children. The same property must be recursively true for all subtrees in this binary tree.
int SplMaxHeap::count()Parameters:This function takes no parameters.Return Value:This function returns the number of nodes present in heap.The following programs illustrate the SplMaxHeap::count() function in PHP:Program 1:
// Create new empty Max Heap
$heap
=
new
SplMaxHeap();
$heap
-> insert (
’ GEEKS’
);
$heap
-> insert (
’gfg’
);
// Print the result
echo
$heap
->
count
();
?>
Exit:2
Program 2:
// Create a new empty Max Heap
$heap
=
new
SplMaxHeap();
// Print the result
echo
$heap
->
count
().
""
;
$heap
-> insert (
’ GEEKS’
);
$heap
-> insert (
’gfg’
);
$heap
-> insert (
’DSA’
);
$heap
-> insert (
’ALGO’
);
$heap
-> insert (
’C’
);
// Print the result
echo
$heap
->
count
();
?>
Exit:0 5
Link: https://www.php.net/manual /en/splheap.count.php
PHP SplHeap count () function: StackOverflow Questions
How to insert newlines on argparse help text?
I"m using argparse
in Python 2.7 for parsing input options. One of my options is a multiple choice. I want to make a list in its help text, e.g.
from argparse import ArgumentParser
parser = ArgumentParser(description="test")
parser.add_argument("-g", choices=["a", "b", "g", "d", "e"], default="a",
help="Some option, where
"
" a = alpha
"
" b = beta
"
" g = gamma
"
" d = delta
"
" e = epsilon")
parser.parse_args()
However, argparse
strips all newlines and consecutive spaces. The result looks like
~/Downloads:52$ python2.7 x.py -h
usage: x.py [-h] [-g {a,b,g,d,e}]
test
optional arguments:
-h, --help show this help message and exit
-g {a,b,g,d,e} Some option, where a = alpha b = beta g = gamma d = delta e
= epsilon
How to insert newlines in the help text?
Answer #1:
Try using RawTextHelpFormatter
:
from argparse import RawTextHelpFormatter
parser = ArgumentParser(description="test", formatter_class=RawTextHelpFormatter)
Is a Python list guaranteed to have its elements stay in the order they are inserted in?
If I have the following Python code
>>> x = []
>>> x = x + [1]
>>> x = x + [2]
>>> x = x + [3]
>>> x
[1, 2, 3]
Will x
be guaranteed to always be [1,2,3]
, or are other orderings of the interim elements possible?
Answer #1:
Yes, the order of elements in a python list is persistent.
Inserting image into IPython notebook markdown
I am starting to depend heavily on the IPython notebook app to develop and document algorithms. It is awesome; but there is something that seems like it should be possible, but I can"t figure out how to do it:
I would like to insert a local image into my (local) IPython notebook markdown to aid in documenting an algorithm. I know enough to add something like <img src="image.png">
to the markdown, but that is about as far as my knowledge goes. I assume I could put the image in the directory represented by 127.0.0.1:8888 (or some subdirectory) to be able to access it, but I can"t figure out where that directory is. (I"m working on a mac.) So, is it possible to do what I"m trying to do without too much trouble?
Answer #1:
Most of the answers given so far go in the wrong direction, suggesting to load additional libraries and use the code instead of markup. In Ipython/Jupyter Notebooks it is very simple. Make sure the cell is indeed in markup and to display a image use:

Further advantage compared to the other methods proposed is that you can display all common file formats including jpg, png, and gif (animations).
Answer #2:
Files inside the notebook dir are available under a "files/" url. So if it"s in the base path, it would be <img src="files/image.png">
, and subdirs etc. are also available: <img src="files/subdir/image.png">
, etc.
Update: starting with IPython 2.0, the files/
prefix is no longer needed (cf. release notes). So now the solution <img src="image.png">
simply works as expected.
how do I insert a column at a specific column index in pandas?
Can I insert a column at a specific column index in pandas?
import pandas as pd
df = pd.DataFrame({"l":["a","b","c","d"], "v":[1,2,1,2]})
df["n"] = 0
This will put column n
as the last column of df
, but isn"t there a way to tell df
to put n
at the beginning?
Answer #1:
see docs: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.insert.html
using loc = 0 will insert at the beginning
df.insert(loc, column, value)
df = pd.DataFrame({"B": [1, 2, 3], "C": [4, 5, 6]})
df
Out:
B C
0 1 4
1 2 5
2 3 6
idx = 0
new_col = [7, 8, 9] # can be a list, a Series, an array or a scalar
df.insert(loc=idx, column="A", value=new_col)
df
Out:
A B C
0 7 1 4
1 8 2 5
2 9 3 6