-1

I’m brand new to coding and have been teaching myself Python. I have been trying to create multiple shopping list, that I can print out in a f-string. My code keeps repeating the f-string by the number of items in the list. No matter what I try, I can’t get the list of items to print.

I would like to be able to create individual shopping list. that I can add and take away items from, that automatically update the f-string when printed.

This is what I have:

Dads_shopping_list = ["Body Wash", "Soda", "Water", "Candy Bar"]

Izaiahs_shopping_list = ["Apples", "Wings", "Chips"]

for Dad in Dads_shopping_list:
    for Izaiah in Izaiahs_shopping_list:
        print(f"Hey can you pick up [Dad] for Dad. And can you bring me back [Izaiahs].")
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • do you want to make it delete the items after priniting it ? – Osama Elsherif Aug 24 '23 at 02:33
  • What output do you want exactly, and what are you getting currently? I just fixed a typo in your code where you had a curly quote instead of a regular quote, but you're not reporting a syntax error so obviously that wasn't a problem, but I'm not sure if the square brackets instead of braces are also a typo. And I'm not sure what the output is supposed to look like anyway. – wjandrea Aug 24 '23 at 02:34
  • Oh and welcome to Stack Overflow! Please take the [tour]. Check out [ask] for tips. You can [edit] your posts to clarify. – wjandrea Aug 24 '23 at 02:35
  • In lieu of clarification, my best guess is you want the output to be `Hey can you pick up Body Wash, Soda, Water, Candy Bar for Dad. And can you bring me back Apples, Wings, Chips.`, in which case there are existing questions about the same thing, e.g. [How would you make a comma-separated string from a list of strings?](/q/44778/4518341) – wjandrea Aug 24 '23 at 02:49
  • Please add a sample of the output you are trying to get. – KRG Aug 24 '23 at 08:38

2 Answers2

0

This is what zip is for. It iterates multiple iterables at once:

for Dad, Izaiah in zip(Dads_shopping_list, Izaiahs_shopping_list):
    print(f"Hey can you pick up {Dad} for Dad. And can you bring me back {Izaiahs}.")
Jab
  • 26,853
  • 21
  • 75
  • 114
  • Thanks for replying. I just tried this. And the console printed out this: Hey can you pick up Body Wash for Dad. And can you pick me up Apples Hey can you pick up Soda for Dad. And can you pick me up Wings Hey can you pick up Water for Dad. And can you pick me up Chips Pytho3IDE run end! – Doney Richardson Aug 24 '23 at 02:40
  • The lists aren't the same length, so `Candy Bar` is missing. And why would you want to repeat the text three times anyway? Lastly, if it *were* just a matter of using `zip`, the question would be a duplicate of [How do I iterate through two lists in parallel?](/q/1663807/4518341) and you should VTC in that case; please don't answer duplicate questions; at least do a little research first. – wjandrea Aug 24 '23 at 02:40
  • I would like to print the statement with the list flowing as if I typed it out. The ability to create a list. And have it print out arranged together. In two separate list. – Doney Richardson Aug 24 '23 at 02:45
0

I assume that you need the output like 'Hey can you pick up -,-,-,dad list items,-,- for Dad. And can you bring me back -,-,-, Izaiah list items,-,- '. You can try the below code by joining the list.

Dads_shopping_list = ["Body Wash", "Soda", "Water", "Candy Bar"]
Izaiahs_shopping_list = ["Apples", "Wings", "Chips"]

print("Hey can you pick up " + ','.join(Dads_shopping_list)+ " for Dad. And can you bring me back " +  ','.join(Izaiahs_shopping_list) + ".")

output

Hey can you pick up Body Wash,Soda,Water,Candy Bar for Dad. And can you bring me back Apples,Wings,Chips.
KRG
  • 655
  • 7
  • 18