পদ্ধতি ১: next() + জেনারেটর
listA = ['', 'top', 'pot', 'hot', ' ', 'shot']
res = next(s for s in listA if s)
print(res) # top
if s খালি স্ট্রিং '' কে False मानে, স্পেস ' ' কে True।
পদ্ধতি ২: filter() (Python 2/3 compatible)
listA = ['', 'top', 'pot', 'hot', ' ', 'shot']
res = next(filter(None, listA))
print(res) # top
filter(None, ...) ফলসি (falsy) ভ্যালুগুলো ফিল্টার করে দেয়।
দ্রষ্টব্য
next()সাথে জেনারেটর সবচেয়ে পাইথনিক।filter(None, ...)পাইথন ৩-এ ইটেরেটর রিটার্ন করে,next()দরকার।- স্পেস
' 'কে খালি না মনে করতে চাইলেif s.strip()ব্যবহার করুন।
আউটপুট
top