KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to have a function that wraps and object in an iterable one in order to allow the clients of the function treat the same way collections and single objects, i did the following: def to_iter(obj): try: iter(obj) return obj except TypeError: return [obj] Is there a pythonic way to do this?, what if obj is a string and i want to treat strings as single objects?, should i use isinstance instead iter ?
Tags (comma-separated)
Save Edits
Cancel