Python Forum
Using values from a list of tuples within a loop
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using values from a list of tuples within a loop
#6
Hi,

Figured out. I was overthinking it (as usual).

This gives the desired result:

srcids = []

src_prefix = '2/9/1/'

def jtrange(start, end):
    return range(start, end + 1)


def srcidrange(srctart, srcend, idstart, idend):
    src = []
    for i in jtrange(srctart, srcend):
        src.append(i)
    ids = []
    for i in jtrange(idstart, idend):
        ids.append(i)
    srcids.extend(zip(src, ids))


srcidrange(10, 25, 1115, 1130)
srcidrange(49, 59, 115, 125)


def gen_map(srctrg, prefix):
    for i, j in srctrg:
        port_numb = str(i // 768)
        port_i8s = str((i//8) % 96)
        chan_numb_gr = str(i % 8)
        print(prefix + port_numb + '/' + port_i8s + '/' + chan_numb_gr + ',' + str(j) + ',' + str(0) + ',' + str(0)) # + ',\n')

gen_map(srcids, src_prefix)
Now I can move on to improving the code.

Best regards,

jtpy
Reply


Messages In This Thread
RE: Using values from a list of tuples within a loop - by jtpy - Mar-11-2018, 08:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copying the order of another list with identical values gohanhango 7 1,172 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,269 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Loop through values and compare edroche3rd 6 704 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Comparing List values to get indexes Edward_ 7 1,192 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,153 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Adding values with reduce() function from the list of tuples kinimod 10 2,685 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,079 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,510 Jul-27-2022, 08:50 PM
Last Post: rob101
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,234 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,923 Mar-27-2022, 07:58 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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