Giter VIP home page Giter VIP logo

Comments (2)

sr-murthy avatar sr-murthy commented on June 3, 2024

@ElliotJH Yes, this came up during testing. In fact, in the original version of the code six wasn't being used, as any dict has itervalues. You can do the following

tiv_elements = tuple(sorted(
                [v for v in cep.itervalues() if v.get('FieldName') and v['FieldName'] == 'TIV'],
                key=lambda v: v['FMTermGroupID']
            ))

The sort is required because the point is to extract an list of TIV elements/fields (these are dict values in cep describing TIV elements which correspond to TIV fields, and these TIV fields describe column names in a CSV exposures file). The point is that the output of this line should be a list of TIV element dicts ordered element names, so for PiWInd the element for WSCV1VAL should be listed before the one for WSCV4VAL, etc.

from oasislmf.

sr-murthy avatar sr-murthy commented on June 3, 2024

@ElliotJH It appears I was wrong - Python 3.6 dicts don't have itervalues, instead have values which appear to be generators. I mainly develop in Python 2.7, and am less familiar with 3+. So the issue you pointed out is still valid. In fact the solution is as follows

tiv_elements = tuple(
    sorted(
        [v for v in canonical_exposures_profile.values() if v.get('FieldName') == 'TIV'],
        key=lambda v: v['FMTermGroupID']
    )
)

So filter in Python 3 produces a generator not a list as in Python 2, so your solution wouldn't work.Tthe common solution is to replace the filter with a plain list, and loop over <dict>.values() not <dict>.itervalues().

This will be fixed in the next release.

from oasislmf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.