How do I access properties of a javascript object if I don’t know the names?

You can loop through keys like this: for (var key in data) { console.log(key); } This logs “Name” and “Value”. If you have a more complex object type (not just a plain hash-like object, as in the original question), you’ll want to only loop through keys that belong to the object itself, as opposed to … Read more

recursion versus iteration

Recursion is usually much slower because all function calls must be stored in a stack to allow the return back to the caller functions. In many cases, memory has to be allocated and copied to implement scope isolation. Some optimizations, like tail call optimization, make recursions faster but aren’t always possible, and aren’t implemented in … Read more

Remove Elements from a HashSet while Iterating [duplicate]

You can manually iterate over the elements of the set: Iterator<Integer> iterator = set.iterator(); while (iterator.hasNext()) { Integer element = iterator.next(); if (element % 2 == 0) { iterator.remove(); } } You will often see this pattern using a for loop rather than a while loop: for (Iterator<Integer> i = set.iterator(); i.hasNext();) { Integer element … Read more

Does pandas iterrows have performance issues?

Generally, iterrows should only be used in very, very specific cases. This is the general order of precedence for performance of various operations: vectorization using a custom Cython routine apply reductions that can be performed in Cython iteration in Python space itertuples iterrows updating an empty frame (e.g., using loc one-row-at-a-time) Using a custom Cython … Read more

C# Iterating through an enum? (Indexing a System.Array)

Array values = Enum.GetValues(typeof(myEnum)); foreach( MyEnum val in values ) { Console.WriteLine (String.Format(“{0}: {1}”, Enum.GetName(typeof(MyEnum), val), val)); } Or, you can cast the System.Array that is returned: string[] names = Enum.GetNames(typeof(MyEnum)); MyEnum[] values = (MyEnum[])Enum.GetValues(typeof(MyEnum)); for( int i = 0; i < names.Length; i++ ) { print(names[i], values[i]); } But, can you be sure that … Read more

Is there a way in Pandas to use previous row value in dataframe.apply when previous value is also calculated in the apply?

First, create the derived value: df.loc[0, ‘C’] = df.loc[0, ‘D’] Then iterate through the remaining rows and fill the calculated values: for i in range(1, len(df)): df.loc[i, ‘C’] = df.loc[i-1, ‘C’] * df.loc[i, ‘A’] + df.loc[i, ‘B’] Index_Date A B C D 0 2015-01-31 10 10 10 10 1 2015-02-01 2 3 23 22 2 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)