char_str = 'abcdefg' # simple breakdown of a string for char in char_str: print char #splitting a string based on an internal character print sub_sets = char_str.split('d') for sub in sub_sets: print 'subsets', sub #splitting a 'comma-separated-value' string on the commas print groups = 'abc,def,ghi' triples = groups.split(',') for trip in triples: print 'split on commas,', trip #same thing for a 'tab-separated-value' string print tab_groups = 'abc\tdef\tghi' tab_triples = tab_groups.split('\t') for trip in tab_triples: print 'tab splits =', trip #here's a longwinded but explicit way to make a list from csv text print groups = 'abc,def,ghi' groups_list = [] print groups_list triples = groups.split(',') for trip in triples: groups_list.append(trip) print "Here's the list:", groups_list for x in range(0,len(groups_list)): #addressing individual elements print "List element", x, ":", groups_list[x] #here is a shorter way to make a list print groups = 'abc,def,ghi' groups_list = groups.split(',') print groups_list for x in range(0,len(groups_list)): #addressing individual elements print "List element", x, ":", groups_list[x] print groups_list[1], 'here it is'
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