查找唯一值并将所有相关值附加到对象数组中

时间:2019-12-10 21:58:06

标签: python arrays django python-3.x object

我想创建一个对象数组。我拥有所有变量,只需要格式化所有值即可。

这些是我的价值观:

namespace GFInterface.ILFI {


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="urn:greenfiling:partner:ws:schema:FilingInfo", ConfigurationName="ILFI.FilingInfo")]
    public interface FilingInfo {
// CODEGEN: Generating message contract since the operation caseSearch is neither RPC nor document wrapped.
        [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getCaseResponseType))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getCaseResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getFilingListResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getFilingList))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(createFilingResponseType))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(createFilingResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(caseSearchResponseType))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(caseSearchResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(advancedCaseSearchResponseType))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(advancedCaseSearchResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getFilingDetailsResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getFilingDetails))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getCourtListResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getCourtList))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getMessageListResponse))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(getMessageList))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(caseActor[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(addon[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(documentSecurity[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(document[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(serviceContact[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(caseCourtEvent[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(complaint[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(actorRole[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(documentActor[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(attachmentAddon[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(filingDocument[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(filingActor[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(filingCharge[]))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(filingServiceContact[]))]
        GFInterface.ILFI.caseSearchResponse1 caseSearch(GFInterface.ILFI.caseSearchRequest request);

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:greenfiling:partner:ws:schema:FilingInfo")]
    public partial class caseSearchResponseType : object, System.ComponentModel.INotifyPropertyChanged {

        private ResponseObject responseObjectField;

        private @case[] courtCasesField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=0)]
        public ResponseObject responseObject {
            get {
                return this.responseObjectField;
            }
            set {
                this.responseObjectField = value;
                this.RaisePropertyChanged("responseObject");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        [System.Xml.Serialization.XmlArrayItemAttribute("courtCase", IsNullable=false)]
        public @case[] courtCases {
            get {
                return this.courtCasesField;
            }
            set {
                this.courtCasesField = value;
                this.RaisePropertyChanged("courtCases");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:greenfiling:partner:ws:schema:FilingInfo")]
    public partial class caseSearchResponse : object, System.ComponentModel.INotifyPropertyChanged {

        private object caseSearchResponse1Field;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("caseSearchResponse", IsNullable=true, Order=0)]
        public object caseSearchResponse1 {
            get {
                return this.caseSearchResponse1Field;
            }
            set {
                this.caseSearchResponse1Field = value;
                this.RaisePropertyChanged("caseSearchResponse1");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:greenfiling:partner:ws:schema:FilingInfo")]
    public partial class caseSearchRequestType : object, System.ComponentModel.INotifyPropertyChanged {

        private user attorneyField;

        private string courtCodeField;

        private string caseNumberField;

        private string partyNameField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=0)]
        public user attorney {
            get {
                return this.attorneyField;
            }
            set {
                this.attorneyField = value;
                this.RaisePropertyChanged("attorney");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=1)]
        public string courtCode {
            get {
                return this.courtCodeField;
            }
            set {
                this.courtCodeField = value;
                this.RaisePropertyChanged("courtCode");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=2)]
        public string caseNumber {
            get {
                return this.caseNumberField;
            }
            set {
                this.caseNumberField = value;
                this.RaisePropertyChanged("caseNumber");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=3)]
        public string partyName {
            get {
                return this.partyNameField;
            }
            set {
                this.partyNameField = value;
                this.RaisePropertyChanged("partyName");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]                                                                                      [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:greenfiling:partner:ws:schema:FilingInfo")]
    public partial class caseSearch : object, System.ComponentModel.INotifyPropertyChanged {

        private caseSearchRequestType caseSearchRequestField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=0)]
        public caseSearchRequestType caseSearchRequest {
            get {
                return this.caseSearchRequestField;
            }
            set {
                this.caseSearchRequestField = value;
                this.RaisePropertyChanged("caseSearchRequest");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class caseSearchRequest {

        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:greenfiling:partner:ws:schema:FilingInfo", Order=0)]
        public GFInterface.ILFI.caseSearch caseSearch;

        public caseSearchRequest() {
        }

        public caseSearchRequest(GFInterface.ILFI.caseSearch caseSearch) {
            this.caseSearch = caseSearch;
        }
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class caseSearchResponse1 {

        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:greenfiling:partner:ws:schema:FilingInfo", Order=0)]
        [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
        public object caseSearchResponse;

        public caseSearchResponse1() {
        }

        public caseSearchResponse1(object caseSearchResponse) {
            this.caseSearchResponse = caseSearchResponse;
        }
    }
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        GFInterface.ILFI.caseSearchResponse1 GFInterface.ILFI.FilingInfo.caseSearch(GFInterface.ILFI.caseSearchRequest request) {
            return base.Channel.caseSearch(request);
        }

        public object caseSearch(GFInterface.ILFI.caseSearch caseSearch1) {
            GFInterface.ILFI.caseSearchRequest inValue = new GFInterface.ILFI.caseSearchRequest();
            inValue.caseSearch = caseSearch1;
            GFInterface.ILFI.caseSearchResponse1 retVal = ((GFInterface.ILFI.FilingInfo)(this)).caseSearch(inValue);
            return retVal.caseSearchResponse;
        }

我的代码:

url =  "Goodreads",
search = "Fantasy",
search_res = [
        {
            "book": "Harry Potter",
            "rating": "10.0"
        },
        {
            "book": "Lord of The Rings",
            "rating": "9.0"
        }
]
url =  "GoodReads",
search = "Dystopia",
search_res = [
        {
            "book": "Handmaids Tale",
            "rating": "9.0"
        },
        {
            "book": "Divergent Series",
            "rating": "8.5"
        }
]
url =  "Kindle",
search = "Fantasy",
search_res = [
        {
            "book": "Twilight Series",
            "rating": "5.5"
        },
        {
            "book": "A Discovery of Witches",
            "rating": "8.5"
        }
]
url =  "Kindle",
search = "Dystopia",
search_res = [
        {
            "book": "Hunger Games",
            "rating": "9.5"
        },
        {
            "book": "Maze Runner",
            "rating": "6.0"
        }
]

我的结果:

    assign_url = url
    the_list = []
    urls = { 
        'the_url' : assign_url,
        'results' : []
    }

    data['search'] = search
    data['results'] = search_res
    urls['results'].append(data)
    the_list.append(urls)
    pprint(json.dumps(the_list))

我希望能够通过the_url对结果进行分组并设置其格式:

预期结果:

 ('[{"the_url": "GoodReads", "results": [{"search": "Fantasy", ''"results": [{"book": "Harry Potter", "Rating": "10.0"}, {"book": "Lord of The Rings", "Rating": "9.0"}]}]}]')
 ('[{"the_url": "GoodReads", "results": [{"search": "Dystopia", ''"results": [{"book": "Handmaids Tale", "Rating": "9.0"}, {"book": "Divergent Series", "Rating": "8.5"}]}]}]')
 ('[{"the_url": "Kindle", "results": [{"search": "Fantasy", ''"results": [{"book": "Twilight Series", "Rating": "5.5"}, {"book": "Divergent Series", "Rating": "8.5"}]}]}]')
 ('[{"the_url": "Kindle", "results": [{"search": "Dystopia", ''"results": [{"book": "Hunger Games", "Rating": "9.5"}, {"book": "A Discovery of Witches", "Rating": "8.5"}]}]}]')

反正我可以按网址将此分组吗?如何修复我的代码?

提前谢谢

0 个答案:

没有答案