Column Python function for a list

Asked

Viewed 205 times

1

I need to create a function that adds columns from one list to another list in the same order by following this structure here (you can use FOR).

def column_to_list(data, index):
    column_list = []
    # código entra aqui nesta parte
    return column_list

How can I do that? I haven’t learned the right to use the arguments in my favor.

An example would be a Gender column, with several entries of Male and Female. I need to take these results from these lines and turn it into a single list.

output = [’M','F','F',’M','F']

  • Opa, put in Portuguese, this Stack Overflow is only in this language.

  • Sorry, now that I realize! I will change!

  • 1

    When it is [Edit] take the opportunity to put examples of results that the function should return.

  • 1

    We still need more details. Please create this list that has several entries of masculine and feminine and from it show us how would be the call of the function that would return the cited output.

  • 1

    What is the format of the input? The output we already have. Pass input examples (the data you enter per parameter in date and index) that we help you to get that output.

1 answer

0

banco = [['Carlos', 'M'],
         ['Frenanda', 'F'],
         ['Gilberto', 'M']]

def column_to_list(data, index):
    column_list = []
        for pessoa in data:
            column_list.append(pessoa[index])
    return column_list

generos = column_to_list(banco, 1)

ñ tested, but 99% of Chace work

Browser other questions tagged

You are not signed in. Login or sign up in order to post.