Home > Net >  Printing and modifying items from list (Py)
Printing and modifying items from list (Py)

Time:12-10

I need to take items from a list, print them below each other add variables next to the printed items

Wanted Output:

`List = [apple, banana]
Variable = Red
Variable2 = Round

Red Round apple
Red Round Banana`

Tried this code

for i in range(0, len(list)):
    print(list[i])

It works well, But I need to add variables to it

CodePudding user response:

You may use python dictionaries to implement your goal

here is a code snippet

items = {
  "apple":'red',
  "banana":'yellow',
}

for key, value in items.items():
  print(f"{value} round {key}")

# output
# red round apple
# yellow round banana

CodePudding user response:

list1 = ['enter code here','enter code here'] list2 = [' enter code here',' enter code here '] num1 = list2[0] list2[1] list1[0] num2 = list2[0] list2[1] list1[1] print(num1) ptint(num2)

  • Related