def create_streams_if_needed(realm, stream_dicts):
 added_streams = []
 existing_streams = []
 for stream_dict in stream_dicts:
  (stream, created) = create_stream_if_needed(realm, stream_dict['name'], invite_only=stream_dict.get('invite_only', False), stream_description=stream_dict.get('description', ''))
  if created:
   added_streams.append(stream)
  else:
   existing_streams.append(stream)
 return (added_streams, existing_streams)

def create_streams_if_needed ( realm , stream_dicts ) : added_streams = [ ] existing_streams = [ ] for stream_dict in stream_dicts : ( stream , created ) = create_stream_if_needed ( realm , stream_dict [ 'name' ] , invite_only = stream_dict . get ( 'invite_only' , False ) , stream_description = stream_dict . get ( 'description' , '' ) ) if created : added_streams . append ( stream ) else : existing_streams . append ( stream ) return ( added_streams , existing_streams )
note that stream_dict["name"] is assumed to already be stripped of whitespace .