python_dictionaries
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python_dictionaries [2023/02/26 03:09] – [tasks] raju | python_dictionaries [2023/08/02 19:41] (current) – [find key corresponding to a value] raju | ||
---|---|---|---|
Line 5: | Line 5: | ||
* [[Convert a dictionary of dataframes to a big dataframe]] | * [[Convert a dictionary of dataframes to a big dataframe]] | ||
* [[Convert a string to a dictionary]] | * [[Convert a string to a dictionary]] | ||
+ | |||
+ | |||
+ | ==== find key corresponding to a value ==== | ||
+ | The following will find the first key corresponding to a given value | ||
+ | < | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | 1 | ||
+ | </ | ||
+ | < | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | 2 | ||
+ | </ | ||
+ | |||
+ | Sample use case: | ||
+ | * In https:// | ||
==== initialize a dictionary ==== | ==== initialize a dictionary ==== | ||
Line 118: | Line 142: | ||
Ref:- http:// | Ref:- http:// | ||
+ | |||
+ | ==== Convert a dictionary to a string ==== | ||
+ | < | ||
+ | $ ipython | ||
+ | Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)] | ||
+ | Type ' | ||
+ | IPython 8.4.0 -- An enhanced Interactive Python. Type '?' | ||
+ | |||
+ | In [1]: | ||
+ | d = {' | ||
+ | |||
+ | In [2]: | ||
+ | import json | ||
+ | s = json.dumps(d) | ||
+ | |||
+ | In [3]: | ||
+ | d | ||
+ | Out[3]: | ||
+ | {' | ||
+ | |||
+ | In [4]: | ||
+ | s | ||
+ | Out[4]: | ||
+ | ' | ||
+ | |||
+ | In [5]: | ||
+ | type(d) | ||
+ | Out[5]: | ||
+ | dict | ||
+ | |||
+ | In [6]: | ||
+ | type(s) | ||
+ | Out[6]: | ||
+ | str | ||
+ | </ | ||
python_dictionaries.1677380996.txt.gz · Last modified: 2023/02/26 03:09 by raju