Hello everyone, How can I, at each, for example, 10 iterations, insert a value into the dictionary that I give it? For example JSON:

{ "id": 1, "name": “A green door”, "price": 12, "tags": } 

My task is that every 10 iteration in tags will be an empty line:

  for i in xrange(100) a['id'] = random.randint(100, 2000000) a['name'] = faker.name() a['price'] = random.randit(10, 20) a['tags'] = random.choice(['te', 'rara','tete', " "]) 

    2 answers 2

    Hi, try this:

     a['tags'] = random.choice(['te', 'rara','tete']) if i % 10 != 0 else " " 
    • Helped spisbo! - max
    • @max is always welcome) - Uladzislau Kaminski
     a['tags'] = (i%10)? random.choice(['te', 'rara','tete']) : " "