Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] How to Use Generator Expressions in Python Dictionaries

#1
How to Use Generator Expressions in Python Dictionaries

Imagine the following scenario:

You work in law enforcement for the US Department of Labor, finding companies that pay below minimum wage so you can initiate further investigations. Like hungry dogs on the back of a meat truck, your Fair Labor Standards Act (FLSA) officers are already waiting for the list of companies that violated the minimum wage law. Can you give it to them?

Here’s the code from my new book “Python One-Liners“:

companies = {'CoolCompany' : {'Alice' : 33, 'Bob' : 28, 'Frank' : 29}, 'CheapCompany' : {'Ann' : 4, 'Lee' : 9, 'Chrisi' : 7}, 'SosoCompany' : {'Esther' : 38, 'Cole' : 8, 'Paris' : 18}} illegal = [x for x in companies if any(y<9 for y in companies[x].values())] print(illegal)


Try it yourself in our interactive Python shell:



https://www.sickgaming.net/blog/2020/04/...tionaries/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tut] How To Kill A Thread In Python? xSicKxBot 0 3 3 hours ago
Last Post: xSicKxBot
  [Tut] Python’s NameError: name ‘xxx’ is not defined — How to Fix This Stupid Bug? xSicKxBot 0 11 10-16-2020, 10:30 PM
Last Post: xSicKxBot
  [Tut] Python IndentationError: unexpected indent (How to Fix This Stupid Bug) xSicKxBot 0 18 10-10-2020, 08:24 PM
Last Post: xSicKxBot
  [Tut] Yield Keyword in Python – A Simple Illustrated Guide xSicKxBot 0 18 10-09-2020, 06:13 PM
Last Post: xSicKxBot
  [Tut] Python Reverse List with Slicing — An Illustrated Guide xSicKxBot 0 29 10-02-2020, 04:24 AM
Last Post: xSicKxBot
  [Tut] How to Remove Duplicates From a Python List While Preserving Order? xSicKxBot 0 31 10-01-2020, 02:21 AM
Last Post: xSicKxBot
  [Tut] How To Update A Key In A Dictionary In Python If The Key Doesn’t Exist? xSicKxBot 0 34 09-29-2020, 09:02 PM
Last Post: xSicKxBot
  [Tut] How to Get the Last Element of a Python List? xSicKxBot 0 36 09-28-2020, 02:36 AM
Last Post: xSicKxBot
  [Tut] How To Format A String That Contains Curly Braces In Python? xSicKxBot 0 31 09-25-2020, 07:51 PM
Last Post: xSicKxBot
  [Tut] Python One Line Dictionary xSicKxBot 0 40 09-21-2020, 05:58 PM
Last Post: xSicKxBot

Forum Jump:

Become a Patron!
[-]
Upcoming Events

[-]
Latest Threads
[Tut] How To Kill A Thread In Python?
Last Post: xSicKxBot
Today 05:40 AM
» Replies: 0
» Views: 3
(Indie Deal) FREE Ghost Sweeper, ? NBA 2...
Last Post: xSicKxBot
Today 05:40 AM
» Replies: 0
» Views: 3
News - Nintendo Is Permanently Reducing ...
Last Post: xSicKxBot
Today 04:13 AM
» Replies: 0
» Views: 2
News - Blade Runner: Enhanced Edition De...
Last Post: xSicKxBot
Today 04:13 AM
» Replies: 0
» Views: 4
Humble Ultimate Fantasy Game Development...
Last Post: xSicKxBot
Yesterday 10:00 PM
» Replies: 0
» Views: 7
Microsoft - Honeywell teams up with Micr...
Last Post: xSicKxBot
Yesterday 09:59 PM
» Replies: 0
» Views: 6
Fedora - Secure NTP with NTS
Last Post: xSicKxBot
Yesterday 09:59 PM
» Replies: 0
» Views: 6
News - Video: First 4 Figures Unboxes It...
Last Post: xSicKxBot
Yesterday 09:59 PM
» Replies: 0
» Views: 6
News - Battlefield 5 Definitive Edition ...
Last Post: xSicKxBot
Yesterday 09:59 PM
» Replies: 0
» Views: 7
(Indie Deal) Alien Cat Bundle, RIDE 4 re...
Last Post: xSicKxBot
Yesterday 05:21 PM
» Replies: 0
» Views: 6

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com

Copyright © SickGaming.net 2012-2020