SORU
20 Kasım 2008, PERŞEMBE


Nasıl rastgele bir liste Python kullanarak bir öğe seçin muyum?

Hadi, bir örnek olarak, aşağıdaki listede var dediler

foo = ['a', 'b', 'c', 'd', 'e']

Bu listeden rastgele bir öğeyi almak için en iyi yolu nedir?

CEVAP
20 Kasım 2008, PERŞEMBE


import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • GOTO Conferences

    GOTO Confere

    3 EKİM 2011
  • katherine gomez

    katherine go

    1 Aralık 2011
  • TheDamnWreckless

    TheDamnWreck

    12 Temmuz 2010