Question

In: Computer Science

python find min in the tuple of dictionaries by date also how to sort this tuple...

python find min in the tuple of dictionaries by date

also how to sort this tuple by effectiveDate

Requests = (

{ "Id": 1, "itemId": 2, "amount": 50, "effectiveDate": "11/15/2015"},

{ "Id": 2, "itemId": 1, "amount": 200, "effectiveDate": "11/20/2015"},

{ "Id": 3, "itemId": 3, "amount": 5000, "effectiveDate": "10/5/2015"},

{ "Id": 4, "itemId": 3, "amount": 600, "effectiveDate": "10/6/2015"}

)

Solutions

Expert Solution

Hi..

-------------------------------------------------------------

working code: find min by effectiveDate

Requests = (

{ "Id": 1, "itemId": 2, "amount": 50, "effectiveDate": "11/15/2015"},

{ "Id": 2, "itemId": 1, "amount": 200, "effectiveDate": "11/20/2015"},

{ "Id": 3, "itemId": 3, "amount": 5000, "effectiveDate": "10/5/2015"},

{ "Id": 4, "itemId": 3, "amount": 600, "effectiveDate": "10/6/2015"})
key_min = min(Requests,key=lambda x:x['effectiveDate'])
key_min

This is screenshot of above code and its output

------------------------------------------------------

Sort the dictionary by effectiveDate

Requests = (

{ "Id": 1, "itemId": 2, "amount": 50, "effectiveDate": "11/15/2015"},

{ "Id": 2, "itemId": 1, "amount": 200, "effectiveDate": "11/20/2015"},

{ "Id": 3, "itemId": 3, "amount": 5000, "effectiveDate": "10/5/2015"},

{ "Id": 4, "itemId": 3, "amount": 600, "effectiveDate": "10/6/2015"})
print("sorted List",sorted(Requests,key=lambda x:x['effectiveDate']))

This is screenshot of above code and its output

Still if you have any doubt or need any kind improvement, please let me know in comment section and if you like, Please upvote.

Thank You !


Related Solutions

Python Coding: Working with Conditions and Dictionaries. 1. Create three dictionaries (student_1, student_2, student_3). 2. In...
Python Coding: Working with Conditions and Dictionaries. 1. Create three dictionaries (student_1, student_2, student_3). 2. In each student dictionary have a key-value for first_name, last_name, and an id number (6 digit), and a current_course. The values assigned to each of these keys is your choice. 3. Also each student will have in their dictionary a list for grades. You will need to add 3 grade values into the list. 4. Provide the student with a message about each assignment grade...
Describe how tuples can be useful with loops over lists and dictionaries, and give Python code...
Describe how tuples can be useful with loops over lists and dictionaries, and give Python code examples. Create your own code examples. Do not copy them from the textbook or any other source. Your descriptions and examples should include the following: the zip function, the enumerate function, and the items method.
For this assignment, find out how to do a bubble sort, selection sort, or insertion sort...
For this assignment, find out how to do a bubble sort, selection sort, or insertion sort in Java. You have the option to choose but you must label (with comments) the algorithm you choose to implement. Convert that algorithm to a generic algorithm and constraint it to only using numerics. Your method should accept an array as a parameter and sort the content of the array. If you wish, you can throw an exception if the contents of the array...
ASAP Use python please!! Write a program including   binary-search and merge-sort in Python. You also need to  modify...
ASAP Use python please!! Write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted and use your variable names and testArrays.  
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many...
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many times each person party in the day. For example def party_freq(dicto:dict) -> [(str,{(int,int,int): int})]: #code here input dict1 ={'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output [('Aaron', {(2000,5,20): 1, (2000,5,21): 1}), ('Baily', {(2000,5,20):...
Write in python: Go through the visualization of the Selection Sort, Bubble Sort and Insertion Sort....
Write in python: Go through the visualization of the Selection Sort, Bubble Sort and Insertion Sort. Write a Pseudo code first for each of these sort methods. After writing the pseudo code write python code from the pseudo code.
In Python, there are different sorting algorithms. Selection Sort, Bubble Sort and Insertion Sort. • Write...
In Python, there are different sorting algorithms. Selection Sort, Bubble Sort and Insertion Sort. • Write a Pseudo code first for each of these sort methods.   • After writing the pseudo code write python code from the pseudo code. • Upload the pseudo code and Python code for each of the three algorithm mentioned.
USE PYTHON to find out What day of the week is a given date? i.e. On...
USE PYTHON to find out What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday Write a function is_leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not. .Then, write a function days_since() which takes 3 input integers day, month, year, representing...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: g. def big_words(text, min_length=10): """ Return a list of big words whose length is at least min_length """ return [] h. def common_words(text, min_frequency=10): """ Return words occurring at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT