We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Guys! I have a question related to Python, in this piece of code of yours - [x for x in numbers if x>0].
What if I wanted to create a "new list" (which contains only negative numbers) from "numbers list" where numbers list is sorted in ascending order. I want to break the loop when x>= 0. So,
a = [x for x in numbers if x >= 0: break]
As you know this syntax is wrong, can you guys suggest me what is the proper way? I am new to Python.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
Guys! I have a question related to Python, in this piece of code of yours - [x for x in numbers if x>0].
What if I wanted to create a "new list" (which contains only negative numbers) from "numbers list" where numbers list is sorted in ascending order. I want to break the loop when x>= 0. So,
As you know this syntax is wrong, can you guys suggest me what is the proper way? I am new to Python.