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
#1
Hello Python forum!

I've been trying to solve this issue long enough to make want to seek help Smile

I've basically created a function that contains a loop that goes through a range of values (among other things) and uses the first values of tuples stored in a list as a condition to continue with the next iteration of the loop. What I haven't been able to figure out is how to use or assign the second values of the tuples to each iteration of the output.

Here's the code:

srcs = 100

srcids = []

src_prefix = '2/9/1/'

jtrange = lambda start, end: 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 in range(srctrg):
        port_numb = str(i // 768)
        port_i8s = str((i//8) % 96)
        chan_numb_gr = str(i % 8)
        if i not in ([x[0] for x in srcids]):
            continue
        print(prefix + port_numb + '/' + port_i8s + '/' + chan_numb_gr + ',' + str(i) + ',' + str(0) + ',' + str(0) + ',\n')

gen_map(srcs, src_prefix)

print([y[1] for y in srcids]) # values that I want to have come out (in order) with the output of the gen_map function where currently str(i) is being used.
Thank you for any help you could provide with this! Wink

Regards,

jtpy
Reply


Messages In This Thread
Using values from a list of tuples within a loop - by jtpy - Mar-08-2018, 10:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove duplicates from dicts with list values wardancer84 27 885 May-27-2024, 04:54 PM
Last Post: wardancer84
  Copying the order of another list with identical values gohanhango 7 1,309 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,375 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Loop through values and compare edroche3rd 6 789 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Comparing List values to get indexes Edward_ 7 1,368 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,354 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Adding values with reduce() function from the list of tuples kinimod 10 2,891 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,178 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,587 Jul-27-2022, 08:50 PM
Last Post: rob101
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,299 Jun-05-2022, 05:24 AM
Last Post: onenessboy

Forum Jump:

User Panel Messages

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