[Python] How to get a value and the value's position in the list

Discussão em 'Python' iniciado por Stack, Julho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of numbers ranging from 1 - 100. And I'd like it when I print a function. It'll print out the random number, and its position within the list.

    Num_List = [6,9,32,39,61,4,28,89,67,14,88,15,73,96,86,55,79,68,76,94,65]

    pos, item = random.choice(list(enumerate(Num_List)))

    print("pos:", pos, "itemvalue:", item)


    I'm wondering if there's a better or even a more efficient way to print this out.

    Continue reading...

Compartilhe esta Página