alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Replacing a variable in a list using a for-loop? [duplicate] in python ?

Replacing a variable in a list using a for-loop? [duplicate] in python ?

In your exampe i is an item in list, not an index:

 cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]

for i, val in enumerate(cards):
    if val == 11:
        cards[i] = 1


print(cards)

55 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online