SORU
17 EYLÜL 2012, PAZARTESİ


Listedeki öğeyi bağlamak için dizeleri - python

Olası Çoğalt:
converting a list to strings in python

Daha basit bir yolu, tek bir dizeye dize listedeki öğeleri bağlamak var mı?

Str kullanabilir miyim.(katıl) listedeki öğeleri birleştirmek için fonksiyon?

E. g. bu ['this','is','a','sentence'] ve bu istenen çıkış giriş this-is-a-sentence

sentence = ['this','is','a','sentence']
sent_str = ""
for i in sentence:
    sent_str  = str(i)   "-"
sent_str = sent_str[:-1]
print sent_str

CEVAP
17 EYLÜL 2012, PAZARTESİ


Kullanım join:

>>> sentence = ['this','is','a','sentence']
>>> '-'.join(sentence)
'this-is-a-sentence'

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BenjiManTV

    BenjiManTV

    20 Mart 2011
  • cdgotx

    cdgotx

    8 Kasım 2011
  • Deany Boii

    Deany Boii

    27 Kasım 2007