#!/usr/bin/env python def expand(s): if not has_braces(s): return s return ' '.join([expand(t) for t in expand_one(s)]) def has_braces(s): if '{' not in s or '}' not in s: return False start, end = brace_indexes(s) return start < end def expand_one(s): start, end = brace_indexes(s) before, after = s[:start], s[end+1:] inside_parts = s[start+1:end].split(',') return (before + inside + after for inside in inside_parts) def brace_indexes(s): return s.index('{'), s.index('}') print expand('a{b,c,d}e') print expand('{0,1}{0,1}{0,1}') print expand('M/win{7,8}/smoothness.{top_10,typical_25}')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question