-1

I am new to Python. I have a flask form that I am submitting. When I submit the form I am trying to post the data to a list as follows:

submittedWords=[]
for v in request.form.items():
    submittedWords.append(v)

This give mt he following:

[('w1', 'first'), ('w2', 'second'), ('w5', 'third'), ('w7', 'fourth'), ('w4', ''), ('w6', ''), ('w3', '')]

Where w1,w2,w3.... is the input name and first,second,third... is the data entered/submitted.

Is this tuples inside a list?

Is there a way to just output the 'data' section such as

['first','second','third','fourth','','','']

Thanks in advance!

davidism
  • 121,510
  • 29
  • 395
  • 339
Sledro
  • 127
  • 1
  • 12

1 Answers1

3

That's what items does; it iterates through the dictionary in the form of (key, value) pairs.

If you just want the values, iterate through those:

for v in request.form.values():
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Perfect. I actaully tried this first and it didn't wok as I must have had an error somewhere else in my code at the time. Just tried it again 2 hours later thanks to you and it worked! WIll mark as correct when it lets me. – Sledro Nov 10 '16 at 22:03
  • Do you consider this a duplicate? I cannot post any more due to this and I don't think its correct. – Sledro Nov 14 '16 at 17:30