0

I have a function that returns three lists into a tuple with three lists,

def dealList(list):
    a, b, c = (list[::3]), list[1::3], list[2::3]
        #here im just taking the first seven elements in the list
        a = a[0:7]
        b = b[0:7]
        c = c[0:7]
        
        sortedarrangement=(a,b,c)
    return sortedarrangement

this function in a sample would return "(['D6', 'HJ', 'H7', 'H9', 'H8', 'S10', 'C2'], ['D9', 'D3', 'DQ', 'S9', 'C6', 'C4', 'D7'], ['S4', 'CJ', 'H5', 'H3', 'C5', 'CQ', 'H6'])"

however i would like to use this tuple in another function which argues if a parameter = 1 for example reorder sortedarrangement as b,a,c for example and then print it out as a list of elements with this new order rather than a tuple, i understand tuples are immutable making this quite a difficult task. Any thoughts?

def reorder(sortedarrangement , inputcolumn):

    s = dealList(list)
    a,b,c = s
    #cardcolumn calls an input function
    card_column = input()
    if card_column == 1:
        l = b,a,c
        print(l)
    elif card_column == 2:
        l = a,b,c
        print(l)
    elif card_column == 3:
        l = a,c,b
        print(l) 

    return l ['D9', 'D3', 'DQ', 'S9', 'C6', 'C4', 'D7']

L at the moment returns

(['D9', 'D3', 'DQ', 'S9', 'C6', 'C4', 'D7'], ['D6', 'HJ', 'H7', 'H9', 'H8', 'S10', 'C2'], ['S4', 'CJ', 'H5', 'H3', 'C5', 'CQ', 'H6'])

here i would like to essentially return a list of the elements in the order of the "L" variable and then be able to put "L" into the deal list function and repeat the process.

The end goal is for a list that returns

['D9', 'D3', 'DQ', 'S9', 'C6', 'C4', 'D7','D6','HJ', 'H7', 'H9', 'H8', 'S10','C2''S4', 'CJ', 'H5', 'H3', 'C5', 'CQ', 'H6']

in its new order

Many thanks

  • 1
    Include some sample input & expected output. – sushanth Aug 09 '20 at 12:46
  • 1
    Does this answer your question? [How do I concatenate two lists in Python?](https://stackoverflow.com/questions/1720421/how-do-i-concatenate-two-lists-in-python) I believe the answer based on `chain` is what you're looking for (note that `list` and `tuple` in this case are very similar) – Elisha Aug 09 '20 at 12:55
  • 1
    See if this helps, https://stackoverflow.com/a/953097/4985099 – sushanth Aug 09 '20 at 12:59
  • @jizhihaoSAMA somehow there was a clash with my edit and the OPs edit. I just wanted to format the code snippets as codeblocks and at this time the added sample input and output was not there, sorry – Phil Leh Aug 09 '20 at 13:06

0 Answers0