instead of using two for loops in python

+1 vote
for pro in product:
    for ser in service:
        if (
            pro['attributes']['code']
            == ser['relationships']['service']['data']['id']
        ):
            service_attributes.append(ser['attributes']['service-parameters'])
        else:
            service_attributes.append(None)
Dec 22, 2019 in Python by anonymous
• 130 points
235 views

1 answer to this question.

+1 vote

This example might help:

for x, y in ((a,b) for a in [1,2,3] for b in [5,6,7]):
  print x, y
answered Dec 24, 2019 by Sumeir

Related Questions In Python

+1 vote
1 answer
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,760 points
587 views
0 votes
1 answer

How do you get the logical xor of two variables in Python?

If you're already normalizing the inputs to ...READ MORE

answered May 29, 2018 in Python by aryya
• 7,350 points
7,498 views
0 votes
1 answer

When to use %r instead of %s in Python? [duplicate]

The %s specifier converts the object using ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 15,390 points
122 views
0 votes
1 answer

How do you get the logical xor of two variables in Python?

What i found is that you can use ...READ MORE

answered Aug 10, 2018 in Python by Priyaj
• 57,530 points
2,750 views
0 votes
1 answer

Avoiding multiple nested for-loops in python

You can replace the three loops with: from ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 57,530 points
96 views
0 votes
1 answer

Avoiding multiple nested for-loops in python

You can replace the three loops with: from ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 57,530 points
887 views
0 votes
2 answers

Avoiding multiple nested for-loops in python

Instead of multi-loop, If you can categorize ...READ MORE

answered Sep 15, 2018 in Python by pedro67657
• 160 points

edited Sep 15, 2018 by Vardhan 4,012 views
0 votes
1 answer

How to print objects of class using print function in Python?

It can be done as shown below: class Element: ...READ MORE

answered Dec 3, 2018 in Python by Nymeria
• 3,540 points

edited Dec 19, 2018 by Nymeria 21,314 views
0 votes
1 answer

How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,060 points
144 views