473,412 Members | 3,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

first of not None

Hello, everybody!

Could someone help me with coding this thing?

I need to put in the var property of the first object from the list
that is not None. Somth like:

foo = first_of([any, beny, riki,]).name

Dont want to ugly if-cascade:

foo = any.name if name is not None else beny.name if beny is not None \
else riki.name if riki is not None
--
Serge Matveenko
mailto:se***@matveenko.ru
http://serge.matveenko.ru/
Oct 9 '08 #1
1 1550
Serge Matveenko a écrit :
Hello, everybody!

Could someone help me with coding this thing?

I need to put in the var property of the first object from the list
that is not None. Somth like:

foo = first_of([any, beny, riki,]).name

Dont want to ugly if-cascade:

foo = any.name if name is not None else beny.name if beny is not None \
else riki.name if riki is not None
def not_none(obj):
return obj is not None

def first_of(seq, predicate=not_none, default=None):
for obj in seq:
if predicate(obj):
return obj
else:
return default

Oct 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Peter Kleiweg | last post by:
I'm still new to Python. All my experience with OO programming is in a distant past with C++. Now I have written my first class in Python. The class behaves exactly as I want, but I would like to...
3
by: reneeccwest | last post by:
<input type="text" size="7" name="test" maxlength="4" value="4Tyourname"> Is there any way I can make first 2 characters as a read only value?
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
4
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
6
by: Lex Hider | last post by:
Hi, Apologies if this is against etiquette. I've just got my first python app up and running. It is a podcast aggregator depending on feedparser. I've really only learnt enough to get this up and...
3
by: Mesut | last post by:
I have written a form in with radio buttons the name is set to orderby and the value is set to KundeVorName and the next value is KundeNachName and it goes so on. I wanna modify my query according...
4
by: neptundancer | last post by:
Hi, to extend my skills, I am learning python. I have written small program which computes math expression like "1+2*sin(y^10)/cos(x*y)" and similar, so far only + - * / ^ sin con tan sqrt are...
0
by: Tim Chase | last post by:
I need to put in the var property of the first object from the list assuming you meant "foo = any.name if ***any*** is not None else beny.name..." If you have a fixed/hard-coded list of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.