Category : dictionary

I am checking the dictionary key If key is present i am extracting role id = ‘L13’ li = [ { ‘id’: ‘L12’, ‘role’: ‘Owner’ }, { ‘id’: ‘L13’, ‘role’: ‘Owner’ } ] Code is below role = ” for each_element in li: if each_element[‘id’] == id: if each_element[‘role’] == ‘Owner’: #print(each_element[‘role’]) role = ‘Owner’ ..

Read more

In the following code, queryResult is a Nested Lists. A nested list means all of the list values had another list. LIKE: [(1024, jkhsa97890),(1025, khka65757),(1025, kjhaksd87987), ….] So with the first loop, we are getting lists fromqueryResult and storing them in the record. ARRAYS STORED IN RECORD: (1024, jkhsasa97890) (1025, khkaada65757) (1025, kjhaksd87987) …. Then ..

Read more

I have a dictionary like that: dictionary = {‘user1’:[{‘product1’:10}, {‘product2’:15}, {‘product3’: 20}], ‘user2’:[{‘product1’:13}, {‘product2’:8}, {‘product3’: 50}]} I want to construct a dataframe where I can see user1 and user2 as indices, product1, product2 and product3 as columns and values of these products should be values of columns. I tried looking here and found this post ..

Read more

I have multiple dictionaries in one variable results. How to return only 1st dictionary value from that? for result in results: print(result) Output is : {‘Title’: ‘John’} {‘Title’: ‘Mark’} {‘Title’: ‘Adam’} {‘Title’: ‘Ethen’} {‘Title’: ‘Tom’} I want to return value of 1st dictionary ‘john’ Source: Python-3x..

Read more

I have a dictionary as a dataset which has the following form dataset {‘key1’: [{ ‘x1’: ‘…’, ‘x2’: ‘…’, ‘x3’: ‘…’ }], ‘key2’: […], ….} I want to extract 100 keys (random) as a txt file. I tried this code dataset.values().to_csv(‘result.txt’) but I have an error ‘dict_values’ object has no attribute ‘to_csv’ How can I ..

Read more