How to convert orderdict into json in python? - django

How to convert below orderedict into regular json ? in python?
[OrderedDict([('ins_short_name', 'MI'), ('beneficiary', []),
('benefit', 65), ('pcp', []), ('benefit_rates', 216),
('added_dependent', []), ('removed_dependent', []), ('ins_name',
'Medical Insurance'), ('plan', {'carrier_logo':
'How to create a DateTime equal to 15 minutes ago?',
'plan_type': 'HMO', 'creation_time': '2019-02-11T06:21:21.743369Z',
'plan_info_details': '', 'rx_coverage': '11', 'id': 65, 'co_pay':
'11', 'contribution_interval': None, 'updation_time':
'2019-02-11T06:21:21.743808Z', 'benefit_display_name': 'Mi1 HMO',
'carrier': 1, 'status': False, 'carrier_name': 'NHP',
'rx_information': None, 'voluntary': False, 'deductible': '11`',
'hsa_qualified_wrap_plan': False, 'benefit': 65,
'terms_and_conditions': None, 'maximum_contribution': None,
'hsa_qualified_base_plan': False, 'primary_care_physician': False,
'plan_info': ''}), ('dependent', []), ('questions',
[OrderedDict([('question', 1), ('question_type', 'radio'),
('identifier', 'Q1'), ('ref', [Decimal('1.00')])]),
OrderedDict([('question', 4), ('question_type', 'plan'),
('identifier', 'Q4'), ('ref', [Decimal('216.00')])])])]),
OrderedDict([('ins_short_name', 'AI'), ('beneficiary',
[OrderedDict([('id', 365), ('first_name', 'rer'), ('last_name',
'ere'), ('relation', 'Spouse'), ('other_relation', None), ('_type',
'Primary'), ('percentage', '100'), ('benefit', 66), ('enrollment',
357), ('creation_time', '2019-02-14T12:04:00.676078Z'),
('updation_time', '2019-02-14T12:04:33.475164Z')])]), ('benefit', 66),
('pcp', []), ('benefit_rates', None), ('added_dependent', []),
('removed_dependent', []), ('ins_name', 'Ancillary Insurance'),
('plan', {'carrier_logo':
'How to create a DateTime equal to 15 minutes ago?',
'plan_type': 'Other', 'creation_time': '2019-02-11T06:24:32.322178Z',
'plan_info_details': '', 'rx_coverage': '', 'id': 66, 'co_pay': '',
'contribution_interval': None, 'updation_time':
'2019-02-11T06:24:32.322541Z', 'benefit_display_name': 'Ai name',
'carrier': 1, 'status': False, 'carrier_name': 'NHP',
'rx_information': None, 'voluntary': True, 'deductible': '',
'hsa_qualified_wrap_plan': False, 'benefit': 66,
'terms_and_conditions': None, 'maximum_contribution': None,
'hsa_qualified_base_plan': False, 'primary_care_physician': False,
'plan_info': ''}), ('dependent', []), ('questions',
[OrderedDict([('question', 12), ('question_type', 'radio'),
('identifier', 'Q12'), ('ref', [Decimal('10.00')])])])])]

Related

how print the function by the location in the list?

data = [
{
'name': 'Instagram',
'follower_count': 346,
'description': 'Social media platform',
'country': 'United States'
},
{
'name': 'Cristiano Ronaldo',
'follower_count': 215,
'description': 'Footballer',
'country': 'Portugal'
},
{
'name': 'Ariana Grande',
'follower_count': 183,
'description': 'Musician and actress',
'country': 'United States'
}]
def dictionary_value():
for value in data:
return value["name"], value["follower_count"],value["description"], value["country"]
Hi, I'm newbie in python and i have a question about dictionary and lists:
i would like that my function dictionary value() will return only the values and print the function by the location in the list, for example: if i want to choose data[2] the outcome should be: 'Ariana Grande', 183,'Musician and actress','United States'. i could not find a way to do it.
Use dict.values method:
def dictionary_value(i):
return list(data[i].values())
Output:
print(dictionary_value(2))
# 'Ariana Grande', 183,'Musician and actress','United States'

request.data changes in every variable

I have this code:
initial_data = dict(request.data.copy())
reserve_data = dict(request.data.copy())
print(initial_data)
for key in initial_data.keys():
merchant_data = initial_data.get(key)
for sub_key in merchant_data.keys():
if sub_key in keys_to_change:
reserve_data[key].pop(sub_key)
reserve_data[key][values_to_change.get(sub_key)] = merchant_data.get(sub_key)
print(initial_data)
As you can see, I am not changing initial_data, but it changes anyway
#before
{'22': {'domain': 'cashier.random.io', 'salt': 'ewrwerwe', 'active': 1, 'separate_cashier': '', 'additional_hosts': {}, 'tradingroom_url': '', 'crm': {'login': '', 'secret': '', 'url': ''}, 'currencies': ['USD', 'EUR'], 'payment_methods': {'12': {}}, 'processors': {}}}
#after
{'22': {'salt': 'ewrwerwe', 'separate_cashier': '', 'additional_hosts': {}, 'tradingroom_url': '', 'crm': {'login': '', 'secret':
'', 'url': ''}, 'currencies': ['USD', 'EUR'], 'payment_methods': {'12': {}}, 'processors': {}, 'host': None, 'is_active': None}}
Is there a way to avoid this? Thanks everybody
initial_data = dict(request.data.copy())
reserve_data = dict(request.data.copy())
does shallow copies of the request data.
If you're internally modifying the contents, you'll need to use copy.deepcopy instead:
initial_data = dict(copy.deepcopy(request.data))
reserve_data = dict(copy.deepcopy(request.data))

unable to insert data in elasticsearch

I have some data in a dictionary. The sample of data is as shown below. when I tried to insert this data of dictionary to elasticsearch. It returns me the error. what I am doing wrong
doc={
'pdpData.addDate': 1453718315L,
'pdpData.ageGroup': 'Adults-Women',
'pdpData.articleAttributes.Body Shape ID': 'Shape ID 424,Shape ID 333,Shape ID 324,Shape ID 443',
'pdpData.articleAttributes.Brand Fit Name': 'NA',
'pdpData.articleAttributes.Closure': 'Elasticated',
'pdpData.articleAttributes.Fabric': 'Polyester',
'pdpData.articleAttributes.Fabric 2': 'NA',
'pdpData.articleAttributes.Fabric 3': 'NA',
'pdpData.articleAttributes.Fit': 'Regular',
'pdpData.articleAttributes.Length': 'Long',
'pdpData.articleAttributes.Occasion': 'Casual',
'pdpData.articleAttributes.Pattern': 'Printed',
'pdpData.articleAttributes.Print / Pattern Type': 'Others',
'pdpData.articleAttributes.Surface Styling / Features': 'NA',
'pdpData.articleAttributes.Type': 'Palazzos',
'pdpData.articleAttributes.Waist Rise': 'Mid',
'pdpData.articleNumber': 'P700418XL-Red-1193441',
'pdpData.articleType.active': True,
'pdpData.articleType.filterOrder': 84L,
'pdpData.articleType.id': 78L,
'pdpData.articleType.isExchangeable': True,
'pdpData.articleType.isFragile': False,
'pdpData.articleType.isHazmat': False,
'pdpData.articleType.isJewellery': False,
'pdpData.articleType.isLarge': False,
'pdpData.articleType.isReturnable': True,
'pdpData.articleType.isTryAndBuyEnabled': True,
'pdpData.articleType.pickupEnabled': True,
'pdpData.articleType.socialSharingEnabled': True,
'pdpData.articleType.typeCode': 'TRSR',
'pdpData.articleType.typeName': 'Trousers',
'pdpData.baseColour': 'Maroon',
'pdpData.brandDetailsEntry.id': 7991L,
'pdpData.brandDetailsEntry.name': 'Trend Arrest',
'pdpData.brandName': 'Trend Arrest',
'pdpData.catalogAddDate': 1468847698L,
'pdpData.catalogDate': 1453964982L,
'pdpData.codEnabled': 'Y',
'pdpData.colour1': 'NA',
'pdpData.colour2': 'NA',
'pdpData.comments': 'westernwearfest-topsellers2016',
'pdpData.crossLinks': [
{
'key': 'More Trousers by Trend Arrest',
'value': 'trousers?f=brand:Trend Arrest::gender:women',
},
{
'key': 'More Maroon Trousers',
'value': 'trousers?f=colour:Maroon::gender:women',
},
{'key': 'More Trousers', 'value': 'trousers?f=gender:women'},
],
'pdpData.discountData.discountAmount': 649.5,
'pdpData.discountData.discountFunding': 'vendor-EOSS',
'pdpData.discountData.discountId': 912071L,
'pdpData.discountData.discountLimit': 30L,
'pdpData.discountData.discountModifiedDate': 1479460272186L,
'pdpData.discountData.discountPercent': 50L,
'pdpData.discountData.discountRuleHistoryId': 1548747L,
'pdpData.discountData.discountRuleId': 912089L,
'pdpData.discountData.discountText.hasFreeItem': False,
'pdpData.discountData.discountText.text': '(50% OFF)',
'pdpData.discountData.discountToolTipText.hasFreeItem': False,
'pdpData.discountData.discountToolTipText.text': 'Buy this item and get <em>50% </em> off',
'pdpData.discountData.discountType': 1L,
'pdpData.discountData.fundingPercentage': 60L,
'pdpData.discountData.icon': 'Flat_Cart_Icon',
'pdpData.discountData.id': 'Flat_Cart_P',
'pdpData.discountData.styleType': 'Style',
'pdpData.discountedPrice': 649L,
'pdpData.fashionType': 'Fashion',
'pdpData.gender': 'Women',
'pdpData.id': 1193441L,
'pdpData.isFlatShotAvailable': 0L,
'pdpData.landingPageUrl': 'Trousers/Trend-Arrest/Trend-Arrest-Maroon-Printed-Palazzo-Trousers/1193441/buy',
'pdpData.masterCategory.active': True,
'pdpData.masterCategory.filterOrder': 0L,
'pdpData.masterCategory.id': 9L,
'pdpData.masterCategory.isExchangeable': True,
'pdpData.masterCategory.isFragile': False,
'pdpData.masterCategory.isHazmat': False,
'pdpData.masterCategory.isJewellery': False,
'pdpData.masterCategory.isLarge': False,
'pdpData.masterCategory.isReturnable': True,
'pdpData.masterCategory.isTryAndBuyEnabled': True,
'pdpData.masterCategory.pickupEnabled': True,
'pdpData.masterCategory.socialSharingEnabled': True,
'pdpData.masterCategory.typeCode': '',
'pdpData.masterCategory.typeName': 'Apparel',
'pdpData.modifiedDate': 1532709720000L,
'pdpData.myntraRating': 0L,
'pdpData.navigationId': 0L,
'pdpData.price': 1299L,
'pdpData.productDescriptors.description.descriptorType': 'description',
'pdpData.productDescriptors.description.value': '<p>A pair of maroon printed mid-rise palazzo trousers, has an elasticated waistband, flared hems</p>',
'pdpData.productDescriptors.materials_care_desc.descriptorType': 'materials_care_desc',
'pdpData.productDescriptors.materials_care_desc.value': '<p>Polyester<br>Machine-wash cold</p>',
'pdpData.productDescriptors.size_fit_desc.descriptorType': 'size_fit_desc',
'pdpData.productDescriptors.size_fit_desc.value': '<p>The model (height 5\'8" and waist 28") is wearing a size 28</p>',
'pdpData.productDescriptors.style_note.descriptorType': 'style_note',
'pdpData.productDescriptors.style_note.value': '<p>Look fabulous and trendy as you step out in this pair of palazzo trousers. Team it with a top or a crop top and pumps for a chic ensemble.</p>',
'pdpData.productDisplayName': 'Trend Arrest Maroon Printed Palazzo Trousers',
'pdpData.productTag': 'Trend Arrest,JIT,ss16launch-women-alloverprintsnew,ss16launch-women-widelegpants,ss16launch-women-alloverprintsnew,HH10FEB16,ss16launch-women-alloverprintsnew,rock-bohemian-style,skirts-for-casual-day-out,nude-pumps-complete-outfit,new-arrivals-offer-10apr,casual-wear-offer-10apr,new-styles-offer-14apr,new-arrival-offer-apr16,grand-premium-30-to-50-off,rs-500-off-22may,new-arrivals-offer-22may,women-western-rfm-2016,rs-500-off-28may,500rs-1jun,rs-500-off-5jun,rs-500-off-june-pn,college-look-print-madness,College-store-pallazos-leggings-women,rs-500-off-26june,college-store,College-store-ethnic-bold-women,500rs-5jul,college-store-view-all,rs-500-off-10jul,rs500-off-17july,500-off-26jul,500-rs-off-10aug,rakhi-store-skirts-palazzos,rs500-off-17aug,inb-august,top-at-august,rs-500-24aug,tat-styles-31aug,off-1000-500-8sep,500-13sep,bottomwear-pre-bbd-sale,bbd-pre-sale-2016,bbd-pre-sale-categories-2016,bbd-one-last,diwali-women-western-oct,wedding-bride-honeymoon-jeans-trousers,myntra-open-coupon-offer,new-customer-Offer,wedding-bride-honeymoon-pack-list-all,ola-offer-nov16,westernwearfest-topsellers2016',
'pdpData.productTypeId': 367L,
'pdpData.recommendations.alsoPopular': [
'append andcat in subtemplate ALL with Women,Apparel',
],
'pdpData.recommendations.matchWith': [
'append andcat in subtemplate ALL with Women',
'append orcat in subtemplate ALL with Shirts',
],
'pdpData.season': 'Summer',
'pdpData.styleImages.back.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.back.imageType': 'back',
'pdpData.styleImages.back.imageURL': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.path': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.relativePath': 'assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutionFormula': 'h_($height),q_($qualityPercentage),w_($width)/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.1080X1440': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.1080X1440Xmini': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.125X161': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.125X161Xmini': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.150X200': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.150X200Xmini': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.180X240': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.180X240Xmini': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.360X480': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.360X480Xmini': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.48X64': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.48X64Xmini': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.resolutions.81X108': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3.jpg',
'pdpData.styleImages.back.resolutions.81X108Xmini': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129093-Trend-Arrest-Women-Trousers-8751453879128667-3_mini.jpg',
'pdpData.styleImages.back.securedDomain': 'https://secureassets.myntassets.com/',
'pdpData.styleImages.back.servingUploaderType': 'CL',
'pdpData.styleImages.back.storedUploaderType': 'CL',
'pdpData.styleImages.back.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.default.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.default.imageType': 'default',
'pdpData.styleImages.default.imageURL': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.path': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.relativePath': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutionFormula': 'h_($height),q_($qualityPercentage),w_($width)/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.1080X1440': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.1080X1440Xmini': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.125X161': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.125X161Xmini': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.150X200': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.150X200Xmini': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.180X240': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.180X240Xmini': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.360X480': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.360X480Xmini': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.48X64': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.48X64Xmini': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.resolutions.81X108': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default.resolutions.81X108Xmini': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.default.securedDomain': 'https://secureassets.myntassets.com/',
'pdpData.styleImages.default.servingUploaderType': 'CL',
'pdpData.styleImages.default.storedUploaderType': 'CL',
'pdpData.styleImages.default.supportedResolutions': '1080X1440,540X720,180X240,360X480,150X200,96X128,81X108,48X64',
'pdpData.styleImages.default_deprecated.domain': 'http://myntra.myntassets.com/',
'pdpData.styleImages.default_deprecated.imageType': 'default_deprecated',
'pdpData.styleImages.default_deprecated.imageURL': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default_deprecated.path': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default_deprecated.relativePath': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.default_deprecated.resolutionFormula': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_($width)_($height).jpg',
'pdpData.styleImages.default_deprecated.resolutions.1080X1440': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_1080_1440.jpg',
'pdpData.styleImages.default_deprecated.resolutions.1080X1440Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_1080_1440_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.125X161': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200.jpg',
'pdpData.styleImages.default_deprecated.resolutions.125X161Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.150X200': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200.jpg',
'pdpData.styleImages.default_deprecated.resolutions.150X200Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_150_200_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.180X240': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_180_240.jpg',
'pdpData.styleImages.default_deprecated.resolutions.180X240Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_180_240_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.360X480': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_360_480.jpg',
'pdpData.styleImages.default_deprecated.resolutions.360X480Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_360_480_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.48X64': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_48_64.jpg',
'pdpData.styleImages.default_deprecated.resolutions.48X64Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_48_64_mini.jpg',
'pdpData.styleImages.default_deprecated.resolutions.81X108': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_81_108.jpg',
'pdpData.styleImages.default_deprecated.resolutions.81X108Xmini': 'http://myntra.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_81_108_mini.jpg',
'pdpData.styleImages.default_deprecated.securedDomain': 'https://myntrawebimages.s3.amazonaws.com/',
'pdpData.styleImages.default_deprecated.servingUploaderType': 'S3',
'pdpData.styleImages.default_deprecated.storedUploaderType': 'S3',
'pdpData.styleImages.default_deprecated.supportedResolutions': '1080X1440,540X720,180X240,360X480,150X200,96X128,81X108,48X64',
'pdpData.styleImages.front.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.front.imageType': 'front',
'pdpData.styleImages.front.servingUploaderType': 'CL',
'pdpData.styleImages.front.storedUploaderType': 'CL',
'pdpData.styleImages.front.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.left.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.left.servingUploaderType': 'CL',
'pdpData.styleImages.left.storedUploaderType': 'CL',
'pdpData.styleImages.left.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.right.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.right.imageType': 'right',
'pdpData.styleImages.right.servingUploaderType': 'CL',
'pdpData.styleImages.right.storedUploaderType': 'CL',
'pdpData.styleImages.right.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleImages.search.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.search.imageType': 'search',
'pdpData.styleImages.search.imageURL': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.path': 'http://assets.myntassets.com/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.relativePath': 'assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutionFormula': 'h_($height),q_($qualityPercentage),w_($width)/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.1080X1440': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.1080X1440Xmini': 'http://assets.myntassets.com/h_1440,q_95,w_1080/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.125X161': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.125X161Xmini': 'http://assets.myntassets.com/h_161,q_95,w_125/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.150X200': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.150X200Xmini': 'http://assets.myntassets.com/h_200,q_95,w_150/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.180X240': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.180X240Xmini': 'http://assets.myntassets.com/h_240,q_95,w_180/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.360X480': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.360X480Xmini': 'http://assets.myntassets.com/h_480,q_95,w_360/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.48X64': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.48X64Xmini': 'http://assets.myntassets.com/h_64,q_95,w_48/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.resolutions.81X108': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1.jpg',
'pdpData.styleImages.search.resolutions.81X108Xmini': 'http://assets.myntassets.com/h_108,q_95,w_81/v1/assets/images/1193441/2016/1/27/11453879129257-Trend-Arrest-Women-Trousers-8751453879128667-1_mini.jpg',
'pdpData.styleImages.search.securedDomain': 'https://secureassets.myntassets.com/',
'pdpData.styleImages.search.servingUploaderType': 'CL',
'pdpData.styleImages.search.storedUploaderType': 'CL',
'pdpData.styleImages.search.supportedResolutions': '1080X1440,540X720,180X240,360X480,150X200,96X128,81X108,48X64',
'pdpData.styleImages.size_representation.imageType': 'size_representation',
'pdpData.styleImages.size_representation.imageURL': 'images/style/sizechart/Trousers_Adults-Women.png',
'pdpData.styleImages.top.domain': 'http://assets.myntassets.com/',
'pdpData.styleImages.top.imageType': 'top',
'pdpData.styleImages.top.supportedResolutions': '1080X1440,540X720,360X480,48X64,81X108',
'pdpData.styleOptions': [
{
'active': True,
'allSize': '28',
'available': True,
'id': 9677369,
'inventoryCount': 27,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 27,
'availableInWarehouses': '28',
'leadTime': 0,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'ON_HAND',
},
},
'skuId': 9677369,
'taxEntry': {'skuId': 9677369, 'taxRate': 5.25},
'unifiedSize': '28',
'unifiedSizeValue': '28',
'value': 'S',
'warehouseIdToItemCountMap': {},
},
{
'active': True,
'allSize': '30',
'available': True,
'id': 9677372,
'inventoryCount': 3,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 3,
'availableInWarehouses': '96',
'leadTime': 3,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'JUST_IN_TIME',
},
},
'skuId': 9677372,
'taxEntry': {'skuId': 9677372, 'taxRate': 5},
'unifiedSize': '30',
'unifiedSizeValue': '30',
'value': 'M',
'warehouseIdToItemCountMap': {},
},
{
'active': True,
'allSize': '32',
'available': True,
'id': 9677375,
'inventoryCount': 4,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 4,
'availableInWarehouses': '28',
'leadTime': 0,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'ON_HAND',
},
},
'skuId': 9677375,
'taxEntry': {'skuId': 9677375, 'taxRate': 5.25},
'unifiedSize': '32',
'unifiedSizeValue': '32',
'value': 'L',
'warehouseIdToItemCountMap': {},
},
{
'active': True,
'allSize': '34',
'available': True,
'id': 9677378,
'inventoryCount': 1,
'name': 'Size',
'skuAvailabilityDetailMap': {
'21': {
'availableCount': 1,
'availableInWarehouses': '28',
'leadTime': 0,
'sellerid': 21,
'sellername': 'Health & Happiness Pvt Ltd',
'storeid': 1,
'supplyType': 'ON_HAND',
},
},
'skuId': 9677378,
'taxEntry': {'skuId': 9677378, 'taxRate': 5.25},
'unifiedSize': '34',
'unifiedSizeValue': '34',
'value': 'XL',
'warehouseIdToItemCountMap': {},
},
],
'pdpData.styleType': 'P',
'pdpData.subCategory.active': True,
'pdpData.subCategory.filterOrder': 0L,
'pdpData.subCategory.id': 29L,
'pdpData.subCategory.isExchangeable': True,
'pdpData.subCategory.isFragile': False,
'pdpData.subCategory.isHazmat': False,
'pdpData.subCategory.isJewellery': False,
'pdpData.subCategory.isLarge': False,
'pdpData.subCategory.isReturnable': True,
'pdpData.subCategory.isTryAndBuyEnabled': True,
'pdpData.subCategory.pickupEnabled': True,
'pdpData.subCategory.socialSharingEnabled': True,
'pdpData.subCategory.typeCode': '',
'pdpData.subCategory.typeName': 'Bottomwear',
'pdpData.usage': 'Casual',
'pdpData.variantName': 'Printed Palazzo Pants',
'pdpData.vat': 5.5,
'pdpData.visualTag': '',
'pdpData.weight': '0',
'pdpData.year': '2016',}
the code which I am trying
res = es.index(index = INDEX_NAME, doc_type=TYPE_NAME, id=i, body = doc)
error is as shown below
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, u'mapper_parsing_exception', u'failed to parse')

Documentation: both data and initial for formset

Django 1.10.
https://docs.djangoproject.com/en/1.10/topics/forms/formsets/#can-order
https://docs.djangoproject.com/en/1.10/topics/forms/formsets/#can-delete
The examples at both of the abovementioned links are as follows:
>>> data = {
... 'form-TOTAL_FORMS': '3',
... 'form-INITIAL_FORMS': '2',
... 'form-MAX_NUM_FORMS': '',
... 'form-0-title': 'Article #1',
... 'form-0-pub_date': '2008-05-10',
... 'form-0-DELETE': 'on',
... 'form-1-title': 'Article #2',
... 'form-1-pub_date': '2008-05-11',
... 'form-1-DELETE': '',
... 'form-2-title': '',
... 'form-2-pub_date': '',
... 'form-2-DELETE': '',
... }
>>> formset = ArticleFormSet(data, initial=[
... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)},
... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)},
... ])
What troubles me: why should we need initial data here? It overburdens the documentation as we don't use the initial data in the example. The only case when we need both data and initial is when we use has_changed().
I'm a newbie. Maybe I don't understand that deep.
How do you think, maybe I should draw the attention of the community at Djangoproject to this problem?

How to get certain keys from a list of dictionaries?

I have a list of dictionaries that I need to extract certain keys from each of the dictionaries in the list.
The list of dictionaries looks like so:
[{u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-94/', u'abbreviation': u'PC', u'site_detail_url': u'http://www.giantbomb.com/pc/3045-94/', u'id': 94, u'name': u'PC'}, {u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-35/', u'abbreviation': u'PS3', u'site_detail_url': u'http://www.giantbomb.com/playstation-3/3045-35/', u'id': 35, u'name': u'PlayStation 3'}, {u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-20/', u'abbreviation': u'X360', u'site_detail_url': u'http://www.giantbomb.com/xbox-360/3045-20/', u'id': 20, u'name': u'Xbox 360'}, {u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-86/', u'abbreviation': u'XBGS', u'site_detail_url': u'http://www.giantbomb.com/xbox-360-games-store/3045-86/', u'id': 86, u'name': u'Xbox 360 Games Store'}]
How would I go about getting all the 'name' keys out of there?
The solution was simple:
for elem in list:
print elem['name']
To get the list of all names, you can use a list comprehension:
>>> L = [{u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-94/', u'abbreviation': u'PC', u'site_detail_url': u'http://www.giantbomb.com/pc/3045-94/', u'id': 94, u'name': u'PC'}, {u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-35/', u'abbreviation': u'PS3', u'site_detail_url': u'http://www.giantbomb.com/playstation-3/3045-35/', u'id': 35, u'name': u'PlayStation 3'}, {u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-20/', u'abbreviation': u'X360', u'site_detail_url': u'http://www.giantbomb.com/xbox-360/3045-20/', u'id': 20, u'name': u'Xbox 360'}, {u'api_detail_url': u'http://www.giantbomb.com/api/platform/3045-86/', u'abbreviation': u'XBGS', u'site_detail_url': u'http://www.giantbomb.com/xbox-360-games-store/3045-86/', u'id': 86, u'name': u'Xbox 360 Games Store'}]
>>> [D['name'] for D in L]
['PC', 'PlayStation 3', 'Xbox 360', 'Xbox 360 Games Store']
If name is not in every dictionary, you can filter the dictionaries:
>>> [D['name'] for D in L if 'name' in D]
['PC', 'PlayStation 3', 'Xbox 360', 'Xbox 360 Games Store']