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]
3 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]3 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
Why is it important to stop climate change?
vampirchik [111]

Answer:

avoiding cutting down tree carelessy

Explanation:

people cutting down tree due to high population in order to find land for building this house so government should encourage people to have less children in the families and train them that when they are cutting trees should plants 10 tree inorder to recovery tree that is take off.

3 0
2 years ago
Read 2 more answers
I logged on today to work on my makeup work. <br> A: True<br> B: False
Lelu [443]
True I don’t really know.
7 0
3 years ago
Read 2 more answers
The intake and exhaust processes are not considered in the p-V diagram of Otto cycle. a) true b) false
vovangra [49]

Answer:

b) false

Explanation:

We know that Otto cycle is the ideal cycle for all petrol working engine.In Otto cycle all process are consider is ideal ,means there is no any ir-reversibility in the processes.

It consist four processes

1-2:Reversible adiabatic compression

2-3:Constant volume heat addition

3-4:Reversible adiabatic expansion

3-4:Constant volume heat rejection

Along with above 4 processes intake and exhaust processes are parallel to each other.From the P-v diagram we can see that all processes.

But actually in general we are not showing intake and exhaust line then it did not mean that in Otto cycle did not have intake and exhaust processes.

6 0
3 years ago
A pumping test was made in pervious gravels and sands extending to a depth of 50 ft. ,where a bed of clay was encountered. The n
Vikki [24]

Answer:per minute from the pumping well, a steady state was attained in about 24 hr. The draw-down at a distance of 10 ft. was 5.5 ft. and at 25 ft. was 1.21 ft.

Explanation:

6 0
2 years ago
When the psychologist simply records the relationship between two variables...
Wewaii [24]
When a psychologist simply records the relationship between two variables without manipulating them, it is called a correlational study.

The observed relationship does not by itself reveal which variable causes the other. This is the directionally problem. Also, the relationship may be due to a third variable controlling both of the observed variables.
8 0
3 years ago
Other questions:
  • Twenty-five wooden beams were ordered or a construction project. The sample mean and he sample standard deviation were measured
    6·1 answer
  • The displacement volume of an internal combustion engine is 3 liters. The processes within each cylinder of the engine are model
    10·1 answer
  • What is the main role of matrix in composites! a)-to transfer stress to the other phases b)- to protect phases from environment
    7·1 answer
  • An 80-percent-efficient pump with a power input of 20 hp is pumping water from a lake to a nearby pool at a rate of 1.5 ft3/s th
    14·1 answer
  • How many kg moles of Sodium Sulphate will contain 10 kg of<br> Sodium?
    10·2 answers
  • Policeman says, "Son, you can't stay here"
    9·1 answer
  • A system samples a sinusoid of frequency 230 Hz at a rate of 175 Hz and writes the sampled signal to its output without further
    9·1 answer
  • To ensure that a vehicle crash is inelastic, vehicle safety designers add crumple zones to vehicles. A crumple zone is a part of
    12·1 answer
  • How to plot 0.45 gradation chart for sieve analysis ?
    12·1 answer
  • When converting liquid level units to sensor output signal units, you should first convert the liquid level units to _____ units
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!