Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:50:49+00:00 2026-06-11T21:50:49+00:00

A = 200 B = -140 C = 400 D = -260 if A

  • 0
A = 200
B = -140
C = 400
D = -260

if A < 0:
   v1 = 0
else:
   v1 = A

if B < 0:
   v2 = 0
else:
   v2 = B

 if C < 0:
   v3 = 0
else:
   v3 = C

if D < 0:
   v4 = 0
else:
   v4 = C

What is the shorthand implementation for the above code structure.?
Is there a better / elegant / convenient way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:50:51+00:00Added an answer on June 11, 2026 at 9:50 pm
    A = 200
    B = -140
    C = 400
    D = -260
    
    v1, v2, v3, v4 = [x if x > 0 else 0 for x in (A, B, C, D)]
    

    If you prefer to use the max function to the python ternary operator, it would look like:

    v1, v2, v3, v4 = [max(x, 0) for x in (A, B, C, D)]
    

    However, if you’re planning on having all of these variables treated the same, you might want to consider putting them in a list/tuple in the first place.

    values = [200, -140, 400, -260]
    values = [max(x, 0) for x in values]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code: Raphael('holder', 400, 400, function() { this.circle(200, 200, 100) this.circle(200, 200, 140)
% link(Origin,Destination,Speed,Length). link(paris,milano,140,360). link(paris,london,200,698). link(berlin,atena,110,714). link(atena,paris,90,370). I need to write this route predicate so
How may I do like that: hash = {} (140..200).each {|n| h[n] = #{n}
200,000,000 is much less than the maximum 32-bit INTEGER, 2,147,483,647.
I have 200 users each user will eventually have a reviewINFO table with certain
I'm having about 200 icons ,which I wanted to display in a treeview on
I have about 200 categories that are nested. I am currently reading the documention
I have a 200 MB text file. But, I need to test my program
Basically I want 200 characters maximum to come up in Console.ReadLine() for user input
I have a dataframe with over 200 columns. The issue is as they were

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.