Categories
Mastering Development

How does this recursive Python code work?

I came across this recursive function that’s supposed flatten a dictionary: def flatten(data, prefix=”, separator=’.’): """Flattens a nested dict structure. """ if not isinstance(data, dict): return {prefix: data} if prefix else data result = {} for (key, value) in data.items(): result.update(flatten(value,_get_new_prefix(prefix, key, separator), separator=separator)) return result def _get_new_prefix(prefix, key, separator): return (separator.join((prefix, str(key))) if prefix […]

Categories
Mastering Development

How to replace NaN values in dataframe based on another list matching values? [closed]

I have data frame consisting of town column and county column. Example shown below: data = {‘Town’: [‘Leeds’, ‘Romley’, ‘St Peter Port’, ‘Dunstable’,’Chirk’ ], ‘County’: [‘Yorkshire’, np.nan, ‘Guernsey’, ‘Bedfordshire’, np.nan], ‘Country’: [‘UK’, ‘UK’,’UK’,’UK’,’UK’]} data = pd.DataFrame (data, columns = [‘Town’,’County’, ‘Country’]) Some county names are missing. I have another data frame with complete UK towns […]

Categories
Mastering Development

associated the list in the on pressed method

when i try to make an if statment in the on Pressed an error occured which is => ‘Equality operator ‘==’ invocation with references of unrelated typesthis is my code and in the text you will see my list i want to make an if statment in onPressed method final List<Movie> movies = [ Movie( […]

Categories
Development

how to get value from raw or xml HTML response by groovy

I’m trying to get userToken from this kind of raw response: HTTP/1.1 200 Date: Wed, 19 Feb 2020 14:48:32 GMT Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Server: nginx Vary: Accept-Encoding Content-Security-Policy: default Content-Language: en-US Content-Encoding: gzip <!DOCTYPE html> <html> <head> <link rel=”icon” href=”https..”/> <meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no”/> <title>Portal</title> </head> <body> <div id=”root”></div> <script […]

Categories
Development

How to display everything from an object including nested objects and arrays?

I have an object which have nested objects and an array. I’m trying to console.log all the data including the data inside the nested object but failing to do so. The result I’m getting shows all the data except the ones which are objects. I get [Object object] instead of those. What I want is […]

Categories
Development

How to create and populate new column in 2nd Pandas dataframe based on condition in 1st df?

I have a pandas dataframe which looks like the following. df1 = {‘City’ :[‘London’, ‘Basel’, ‘Kairo’], ‘Country’: [‘UK’,’Switzerland’,’Egypt’]} City Country 0 London UK 1 Basel Switzerland 2 Kairo Egypt Now I want to assign a new column called ‘Continent’ that should be filled based on the values. So df2 should look like: City Country Continent […]

Categories
Development Firebase Kotlin

kotlin-firebase-retrieving corresponding data from child selected in spinner

I am using kotlin and using and I am trying to retrieve data from a STATIC list in firebase based on a selected I have made with a spinner. I have a list which contains countries and their corresponding continent. after i select the country using a searchable spinner, I can successfully store my selection […]

Categories
Development JSON

Split JSON array into an object per line

Basically, I have a really large JSON file I need to parse, and while searching, I came across this answer. The only problem is I don’t know how to format my JSON array into a single object per line. Is there a straightforward Javascript/Ubuntu way to do this? (I’ve used jq in the past and […]