O
O
Oleg Petrov2017-10-12 11:43:04
SQL
Oleg Petrov, 2017-10-12 11:43:04

Why doesn't the list transformation function work?

I give the input of the function a list that it transforms:
1) First it leaves only even numbers
2) It divides the remaining even numbers by 2
The function does nothing with the list, tell me why?
I enter 2 3 4. I expect the result [1, 2], but in fact the same list [2, 3, 4]

def modify_list(l):
    m =[]
    for z in l:
        if  z % 2 == 0:
            m.append(int(z // 2))
    return m
l = [int(i) for i in input().split()]
modify_list(l)
print(l)

Answer the question

In order to leave comments, you need to log in

6 answer(s)
E
Eugene, 2019-07-09
@eugeneledenev

Looks like my subd doesn't support from
, here's what it looks like if it works:

UPDATE 
  oc_decomo_items di
  LEFT JOIN oc_product p 
  ON p.product_id=di.product_id
SET 
  di.product_id=NULL,
  di.add_to_shop=0
WHERE 
  di.product_id IS NOT NULL 
  AND p.product_id IS NULL

A
Andrey, 2019-07-09
@VladimirAndreev

UPDATE does not have a FROM clause.

R
Ruslan., 2019-07-09
@LaRN

Here the condition is strange:
di.product_id IS NOT NULL
AND p.product_id IS NULL
At the same time:
p.product_id=di.product_id
Here one field is always required . NULL, while the second is always non-NULL and the p.product_id=di.product_id condition will never be met.

A
Alexander, 2017-10-12
@Smeilz1

Works for third version of python:

def modify_list(l):
    tmp = [el for el in l if not el%2]
    l.clear()
    l.extend(tmp)
    for i in range(len(l)):
        l[i] //= 2
    
    
l = [int(i) for i in input().split()]
modify_list(l)
print(l)

PS: By the way, PEP8 strongly recommends never using l as a single-letter variable name. It is better to use a different name, or at least use a capital L.
Never use the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), or 'I' (uppercase letter eye) as single character variable names.
In some fonts, these characters are indistinguishable from the numerals one and zero. When tempted to use 'l', use 'L' instead.

T
Twelfth Doctor, 2017-10-12
@verdex

def modify_list(l):
    m =[]
    for z in l:
        if  z % 2 == 0:
            m.append(int(z // 2))
    return m
l = [int(i) for i in input().split()]
a = modify_list(l)
print(a)

E
Egor Tyuvaev, 2017-10-12
@CulHatsker

You are printing the original list, not the modified one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question