Q
?
A -
Informatica
search
Login
Remember
Register
New Activity
Questions
Unanswered
Tags
Categories
Users
Course
News
FAQs
Do you need any help?
Ask a Question
Notice Board
NEXT EXAMS
Current grades at 28/3/22
Exams and Covid-19
BUG BOUNTY / IMPROVEMENTS
Code coverage
DOWNVOTES
Course info
Course rules
Zoom links
Unit 1, log of the lectures
Unit 1, class exercises
Unit 1, video recordings
Unit 2, log of the lectures
Unit 2, additional exercises
Unit 2, video recordings
Teaching material
Getting started
Teaching assistants
Booking tutoring
Programming exercises
Exams
Test
Grades
Attachments
HW6 recovery
link
HW8 recovery
link
HW8 required
link
HW7 optional
link
HW6 required
check
link
HW4 recovery
link
HW5 optional
link
HW2 recovery
link
HW4 required
check
link
HW3 optional
link
HW2 required
check
link
HW1 optional
link
192
questions
394
answers
416
comments
304
users
Related questions
How can I solve this "[[1,2,3],[3,4,5]]" = [[1,2,3],[3,4,5]] (from str to int) ?
How can I lose a sad smiley in Q2A?
How to fix images.visd() : [ ValueError: invalid literal for int() with base 10: 'a' ]
How to reduce length of a for loop, if it is possible.
Most popular tags
homework
exam
grades
homework2
test
recovery
error
homework8
hw2
tests
hw
lectures
secret-tests
announcements
bug
exam-18-2-22
homework4
hw1
hw4
optional
q2a
required
#homework
anaconda
exam-1-4-22
homework6
hw4req
hw5opt
hw6rec
hw8
hw8req
libraries
programming
reserved-exam
solutions
vm
2nd-chance
esonero
exam-20-6-22
exam-28-1-22
exercises
exploit
help
homework5
hw2req
hw4rec
hw6req
hw8rec
news
peer-assessment
How can I add Nothing to a list?
ruben.ciranni
(4650 points)
7
13
31
asked
Dec 11, 2021
in
Programming in Python
by
ruben.ciranni
(
4,650
points)
Is there a way to append a blank item to a list? I don't want to append the value None, but really nothing.
Ex.
>>> a = [1,2,3,4]
>>> a.append(None)
>>> a
#what I would like to happen
[1,2,3,4]
#what happens
[1,2,3,4,None]
130
views
30
3 Answers
Best answer
gabrimat
(5630 points)
2
3
25
answered
Dec 11, 2021
by
gabrimat
(
5,630
points)
selected
Dec 11, 2021
by
ruben.ciranni
Use sum instead of append and sum the empty list [] in case.
11
comment
Lorenzo_Pellegrino
(770 points)
2
5
10
commented
Dec 11, 2021
by
Lorenzo_Pellegrino
(
770
points)
Can you explain further?
gabriel.bustamante
(2540 points)
3
5
20
commented
Dec 11, 2021
by
gabriel.bustamante
(
2,540
points)
>>> a = [1,2,3,4]
>>> b = []
>>> a + b
[1, 2, 3, 4]
Keep in mind that "+" and .append() are not always interchangeable
andrea.sterbini
(172780 points)
513
935
1789
commented
Dec 12, 2021
by
andrea.sterbini
(
172,780
points)
+ and append are radically different
+ creates a new list
append changes the initial list
+= changes the initial list
Please
log in
or
register
to add a comment.
James_F
(4750 points)
7
14
37
answered
Dec 11, 2021
by
James_F
(
4,750
points)
just do NOT append anything
12
comment
Please
log in
or
register
to add a comment.
Quellocinese
(2700 points)
2
4
22
answered
Dec 11, 2021
by
Quellocinese
(
2,700
points)
have you thought about a try exception and just don't append if appending None
11
comment
Please
log in
or
register
to add a comment.