Characters allowed in php array keys?

According to the manual: The key can either be an integer or a string. The value can be of any type. Additionally the following key casts will occur: Strings containing valid integers will be cast to the integer type. E.g. the key “8” will actually be stored under 8. On the other hand “08” will … Read more

Remove all elements from array that do not start with a certain string

Functional approach: $array = array_filter($array, function($key) { return strpos($key, ‘foo-‘) === 0; }, ARRAY_FILTER_USE_KEY); Procedural approach: $only_foo = array(); foreach ($array as $key => $value) { if (strpos($key, ‘foo-‘) === 0) { $only_foo[$key] = $value; } } Procedural approach using objects: $i = new ArrayIterator($array); $only_foo = array(); while ($i->valid()) { if (strpos($i->key(), ‘foo-‘) === … Read more

Java AES and using my own Key

Edit: As written in the comments the old code is not “best practice”. You should use a keygeneration algorithm like PBKDF2 with a high iteration count. You also should use at least partly a non static (meaning for each “identity” exclusive) salt. If possible randomly generated and stored together with the ciphertext. SecureRandom sr = … Read more

Initializing a dictionary in python with a key value and no corresponding values

Use the fromkeys function to initialize a dictionary with any default value. In your case, you will initialize with None since you don’t have a default value in mind. empty_dict = dict.fromkeys([‘apple’,’ball’]) this will initialize empty_dict as: empty_dict = {‘apple’: None, ‘ball’: None} As an alternative, if you wanted to initialize the dictionary with some … Read more

NLTK python error: “TypeError: ‘dict_keys’ object is not subscriptable”

Looks like you are using Python 3. In Python 3 dict.keys() returns an iterable but not indexable object. The most simple (but not so efficient) solution would be: vocab = list(fdist1.keys())[:200] In some situations it is desirable to continue working with an iterator object instead of a list. This can be done with itertools.islice(): import … Read more

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