Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested for loops
#1
Hey Py community,
Im very new to Python so I trying to learn by giving myself small projects at work. Here is a basic version of what I'm
trying to do. The output I'm looking for is:
Output:
Gi0/1 Gi0/3 Gi0/4 Gi0/5 Gi0/6 Gi0/7 Gi0/9
But the code and the output I getting is this.

code:
a = ("Gi0/1", "Gi0/2", "Gi0/3", "Gi0/4", "Gi0/5", "Gi0/6", "Gi0/7", "Gi0/8", "Gi0/9", "Gi0/10")
b = ("Gi0/2", "Gi0/8", "Gi0/10")

for num_a in a: 
    for num_b in b:
        if num_a == num_b:
            print(num_a)
Output:
Output:
Gi0/2 Gi0/8 Gi0/10
I also tried if not num_a == num_b:

If someone can point me in the right direction I would greatly appreciate it.

Danny
Reply


Messages In This Thread
Nested for loops - by d79danny - Oct-04-2019, 09:09 PM
RE: Nested for loops - by ichabod801 - Oct-04-2019, 09:35 PM
RE: Nested for loops - by d79danny - Oct-04-2019, 10:13 PM
RE: Nested for loops - by newbieAuggie2019 - Oct-04-2019, 10:35 PM
RE: Nested for loops - by ichabod801 - Oct-04-2019, 10:24 PM
RE: Nested for loops - by d79danny - Oct-04-2019, 10:52 PM
RE: Nested for loops - by newbieAuggie2019 - Oct-04-2019, 11:00 PM
RE: Nested for loops - by ichabod801 - Oct-05-2019, 12:24 AM
RE: Nested for loops - by newbieAuggie2019 - Oct-05-2019, 02:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  reduce nested for-loops Phaze90 11 2,068 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,804 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,727 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  breaking out of nested loops Skaperen 3 1,318 Jul-18-2022, 12:59 AM
Last Post: Skaperen
  Break out of nested loops muzikman 11 3,527 Sep-18-2021, 12:59 PM
Last Post: muzikman
  How to break out of nested loops pace 11 5,570 Mar-03-2021, 06:25 PM
Last Post: pace
  Nested for Loops sammay 1 10,518 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,557 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Python beginner - nested while loops mikebarden 1 1,924 Jun-01-2020, 01:04 PM
Last Post: DPaul
  best way out of nested loops? Skaperen 7 3,928 May-30-2020, 05:20 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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