Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Break out of nested loops
#7
Yes, you are correct. I need to pass a selector to the function. I just didn't know how far I wanted to go with this example. I always try to return a data type that gives the user the option to do what they want with it. Like returning formatted strings is a terrible idea.

I should have returned a list. Then filtered the duplicates by converting it to a set, outside a function.

I will make some adjustments to my code based on your suggestions.

I need to focus on reusable code and return basic data types.

I use comprehension when I need to filter and map at the same time. Even at the cost of a little overhead.


list_multiply = [1, 2, 3, 4, 5, 6, 7, 8]
list_inter = [ x * x for x in list_multiply if x > 2]
instead of using the map and filter functions

That type of thing.
Reply


Messages In This Thread
Break out of nested loops - by muzikman - Sep-15-2021, 06:02 PM
RE: Break out of nested loops - by muzikman - Sep-16-2021, 02:34 PM
RE: Break out of nested loops - by deanhystad - Sep-16-2021, 03:37 PM
RE: Break out of nested loops - by muzikman - Sep-16-2021, 05:53 PM
RE: Break out of nested loops - by muzikman - Sep-16-2021, 06:00 PM
RE: Break out of nested loops - by deanhystad - Sep-16-2021, 07:31 PM
RE: Break out of nested loops - by muzikman - Sep-17-2021, 03:06 PM
RE: Break out of nested loops - by muzikman - Sep-17-2021, 04:18 PM
RE: Break out of nested loops - by deanhystad - Sep-17-2021, 05:34 PM
RE: Break out of nested loops - by muzikman - Sep-17-2021, 05:48 PM
RE: Break out of nested loops - by deanhystad - Sep-17-2021, 07:31 PM
RE: Break out of nested loops - by muzikman - Sep-18-2021, 12:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  for loops break when I call the list I'm looping through Radical 4 926 Sep-18-2023, 07:52 AM
Last Post: buran
  reduce nested for-loops Phaze90 11 1,959 Mar-16-2023, 06:28 PM
Last Post: ndc85430
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,745 Aug-19-2022, 11:07 AM
Last Post: dm222
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,632 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  breaking out of nested loops Skaperen 3 1,256 Jul-18-2022, 12:59 AM
Last Post: Skaperen
  How to break out of nested loops pace 11 5,443 Mar-03-2021, 06:25 PM
Last Post: pace
  Nested for Loops sammay 1 9,115 Jan-09-2021, 06:48 PM
Last Post: deanhystad
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,486 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Conditionals, while loops, continue, break (PyBite 102) Drone4four 2 3,003 Jun-04-2020, 12:08 PM
Last Post: Drone4four
  Python beginner - nested while loops mikebarden 1 1,889 Jun-01-2020, 01:04 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020