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
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
188
questions
394
answers
416
comments
303
users
Related questions
How to fix images.visd() : [ ValueError: invalid literal for int() with base 10: 'a' ]
error on Spyder update to 5.1.5 version
How can I add Nothing to a list?
Spyder Lagging on MacBook (How to solve the problem)
How can I lose a sad smiley in Q2A?
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-28-1-22
exercises
exploit
help
homework5
hw2req
hw4rec
hw6req
hw8rec
news
peer-assessment
python
How can I solve this "[[1,2,3],[3,4,5]]" = [[1,2,3],[3,4,5]] (from str to int) ?
M
Mahfuj
(690 points)
1
2
3
asked
Nov 15, 2021
in
News
by
Mahfuj
(
690
points)
v="[[1,2,3],[3,4,5]]"
i used int(v) but it's not working it shows
ValueError: invalid literal for int() with base 10: '[[1,2,3],[3,4,5]]'
is there any way to turn '[[1,2,3],[3,4,5]]' to [[1,2,3],[3,4,5]] ?
141
views
error
22
1
answer
Please
log in
or
register
to answer this question.
1 Answer
Quellocinese
(2700 points)
2
4
22
answered
Nov 15, 2021
by
Quellocinese
(
2,700
points)
First of all, how did you get a string o lists...
the int() casting works on literals that can be converted like "1" or "2" --> 1 or 2
you should't make the list of lists into a string so you can work with the the 2d array waaaaay more easily by looping through each element of each list in the matrix to cast the single values to int.
But i see that the lists you have in the string in v are already in int() type, so I suggest you to take the lists you generated and NOT put them in a string variable.
7
comment
M
Mahfuj
(690 points)
1
2
3
commented
Nov 15, 2021
by
Mahfuj
(
690
points)
reshown
Nov 15, 2021
by
Mahfuj
lines2=[[1, 2, 3],[3, 4, 5]]
v=''.join(str(lines2).split(' '))
I did this for removing the whitespace from lines2 then v turns into string
I am trying to print(v[0]) it gives '[' not [1,2,3]
but my fact is not that my question is" Is it possible to turn '[[1,2,3],[3,4,5]]' to [[1,2,3],[3,4,5]] ?" ( Yes or Not )
andrea.sterbini
(172680 points)
511
927
1776
commented
Nov 15, 2021
by
andrea.sterbini
(
172,680
points)
possibly by using the builtin function eval
Exyss
(21390 points)
1
2
79
commented
Nov 16, 2021
by
Exyss
(
21,390
points)
You can either use the eval( ) method as the professor said or you can make your own parsing function, which however would probably get more complex/slow
andrea.sterbini
(172680 points)
511
927
1776
commented
Nov 16, 2021
by
andrea.sterbini
(
172,680
points)
we will see how to write a recusive parser for this kind of expressions in december
Please
log in
or
register
to add a comment.