擅长:python、mysql、java
<p>正如其他人提到的,<a href="https://docs.python.org/3.3/library/functions.html#zip" rel="nofollow noreferrer">zip()</a>函数特别有用。在python中使用<code>.format()</code>(<a href="https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting" rel="nofollow noreferrer">link</a>)和<a href="https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files" rel="nofollow noreferrer">writing out to a file</a>也很重要</p>
<pre><code>l1 = ['Cappuccino with Milk Chocolate Cookie', 'Cappuccino with Double Chocolate Cookie', 'Latte with Milk Chocolate Cookie', 'Latte with Double Chocolate Cookie', 'McFizz Guava', 'Date Pie', 'Spicy McCrispy Deluxe - Regular Meal', 'McChicken - Regular Meal', 'Curly Fries', 'Salted Caramel Shake']
l2 = ['Rs 288', 'Rs 288', 'Rs 288', 'Rs 288', 'Rs 159', 'Rs 195', 'Rs 416', 'Rs 416', 'Rs 239', 'Rs 239']
outstring = ''
for elem1, elem2 in zip(l1, l2):
s = 'Title : {}\nPrice : {}\n\n'.format(elem1, elem2)
outstring += s
fn = 'meal.txt'
with open(fn, 'w') as f:
f.write(outstring)
</code></pre>