Skip to content

Instantly share code, notes, and snippets.

@doobeh
Created January 30, 2013 15:03
Show Gist options
  • Select an option

  • Save doobeh/4673856 to your computer and use it in GitHub Desktop.

Select an option

Save doobeh/4673856 to your computer and use it in GitHub Desktop.
example = [(1, u'FromFlask', u'file1.ext', u"['file2.ext']", u'WCP', u'WR_HS', u'email@hotmail.com', u'nothing happens', u'2013-01-3009:15:18.628922', u'None'), (2, u'FromFlask', u'file1.ext', u"['file2.ext']", u'WCP', u'WR_HS', u'email@hotmail.com', u'nothing happens', u'2013-01-3009:15:29.963847', u'None'), (3, u'FromFlask', u'file1.ext', u"['file2.ext']", u'WCP', u'WR_HS', u'email@windriver.com', u'nothing happens', u'2013-01-3009:21:16.275987', u'None'), (4, u'Cody', u'file1.ext', u"['inp_test.ext']", u'WCA', u'WR_HS', u'email@windriver.com', u'nothing happens', u'2013-01-3009:34:03.196901', u'None')]
[(x, x) for x in example]
# is the same as:
output = list()
for x in example:
output.append((x,x))
# because each 'x' is an entire set, e.g:
# (1, u'FromFlask', u'file1.ext', u"['file2.ext']", u'WCP', u'WR_HS', u'email@hotmail.com', u'nothing happens', u'2013-01-3009:15:18.628922', u'None')
# you end up with:
[(example[0],example[0]), (example[1],example[1])]
# where example[0] is a set of many values, wtforms just wants one, so we need to pull out just the filename:
output = [(x[2], x[2]) for x in example)
# which should give you:
[(u'file1.ext',u'file1.ext'),(u'file1.ext',u'file1.ext')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment