1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paraphin [41]
4 years ago
7

A manager has a list of items that have been sorted according to an item ID. Some of them are duplicates. She wants to add a cod

e to the database that assigns a 1 to the item if it is​ unique, and if there are​ duplicates, assigns the number of the duplicate. An example is shown below. The first two items are​ unique, so the repeat code is 1.​ However, Item ID 37699 is listed six​ times, so the codes are assigned from 1 to​ 6, and so on. Explain how to assign the correct code using an IF statement.
Engineering
1 answer:
ruslelena [56]4 years ago
6 0

Answer:

The solution code is written in Python:

  1. items = [{"id": 37697, "code": ""},{"id": 37698, "code": ""},{"id": 37699, "code": ""},{"id": 37699, "code": ""}, {"id": 37699, "code": ""},
  2. {"id": 37699, "code": ""},{"id": 37699, "code": ""},{"id": 37699, "code": ""},{"id": 37700, "code": ""} ]
  3. items[0]["code"] = 1
  4. for i in range(1, len(items)):
  5.    if(items[i]["id"] == items[i-1]["id"]):
  6.        items[i]["code"] = items[i-1]["code"] + 1
  7.    else:
  8.        items[i]["code"] = 1
  9. print(items)

Explanation:

Firstly, let's create a list of dictionary objects. Each object holds an id and a code (Line 1-2). Please note all the code is initialized with zero at the first beginning.

Next, we can assign 1 to the <em>code</em> property of items[0] (Line 4).

Next, we traverse through the items list started from the second element (Line 6). We set an if condition to check if the current item's id is equal to the previous item (Line 7). If so, we assign the previous item's code + 1 to the current item's code (Line 8). If not, we assign 1 to the current item's code (Line 10).

At last, we print out the item (Line 12) and we shall get

[{'id': 37697, 'code': 1}, {'id': 37698, 'code': 1}, {'id': 37699, 'code': 1}, {'id': 37699, 'code': 2}, {'id': 37699, 'code': 3}, {'id': 37699, 'code': 4}, {'id': 37699, 'code': 5}, {'id': 37699, 'code': 6}, {'id': 37700, 'code': 1}]

 

You might be interested in
What type of slab and beam used in construction of space neddle​
Sav [38]

jrjrkeekkekekkwkkakkllalllalallalllalalaallalalaalalalalalallallallllallalalallaaallalallllllallllllllalaalalalaaaaalalaaaaaaalgjgiejxpwunfifjruritiririirieoeowowowowowowowowooeowowowoeeoeowowowowowowowoowowwowowowoozoeisiaokseekxidjdkdjfidjfjdjfjfjrifjrifjdirjdjrjfjrjfjrjfjrfuejwwuxmaneanfjkaosndjxieneamalhaqzeeshanvhorahfuensiwjakaksjdhfhfnfhfndjxnxmakaalalalwlwlwwow

5 0
3 years ago
The recommended time weighted average air concentration for occupational exposure to water soluble hexavalent chromium (Cr VI) i
sergejj [24]

Answer:

CDI= 1.393 × 10^-3 mg/kg.d

Explanation:

The solution and complete explanation for the above question and mentioned conditions is given below in the attached document.i hope my explanation will help you in understanding this particular question.

8 0
4 years ago
A sealed, rigid vessel of 2 m3 contains a saturated mixture of liquid and vapor R-134a at 10C. If it is heated to 50 C, the liqu
Iteru [2.4K]

Answer:  93.30kg

Explanation:

in the attachment

8 0
4 years ago
Which of the following fluid power systems is portable and human-scale?
meriva

Answer:

a fluid power engine okk done please

7 0
2 years ago
Read 2 more answers
Name the five points where product should be scanned during it's path throughout the warehouse.
Oxana [17]

Answer and Explanation:

A warehouse can be defined as a place:

is a spot or building, where the articles are kept, put away or in some cases prepared.  

Depending on the sort of use, the checkpoints may fluctuate.  

There can be numerous sorts, for example, pressing, railroad wagon, cool stockpiling, and so on.  

Suppositions are caused in regards to each shape and a few checkpoints for an item to can be summed up.  

  • The point of entry, where it ought to be through into the product house.  
  • Security checkpoint, where the item belonging is to be protected.  
  • Palletized segment, where the item is to be put in a spot and it determines the location of that item in the house.  
  • Quality or bundling segment, where the item must be tried and improved.  
  • Leave segment, through which it must be taken out for further procedures.  

7 0
4 years ago
Other questions:
  • Consider a 2-shell-passes and 8-tube-passes shell-and-tube heat exchanger. What is the primary reason for using many tube passes
    6·1 answer
  • An electronic device dissipating 25 W has a mass of 20 g and a specific heat of 850 J/kg·0K. The device is lightly used, and it
    9·1 answer
  • What is the difference between tension and compression?
    9·1 answer
  • The drag coefficient of a vehicle increases when its windows are rolled down or its sunroof is opened. A sports car has a fronta
    13·2 answers
  • Suppose that tank holds 1% liquid water by volume and 99% vapor water by volume at a temperature of 185oC. What is the quality?
    10·1 answer
  • A disk of radius 2.1 cm has a surface charge density of 5.6 µC/m2 on its upper face. What is the magnitude of the electric field
    15·1 answer
  • Digital leaders are people who __ others down a particular path.
    13·2 answers
  • Please answer fast. With full step by step solution.​
    14·1 answer
  • What are the ropes of secretaries and treasures in a meeting​
    15·1 answer
  • Chemical engineers determine how to transport chemicals.<br> O True<br> False
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!