how can I input a list of lists to make a matrix and change columns by using map function












0















I can't get input a list of lists. I get this error :



TypeError                                 Traceback (most recent call last)
<ipython-input-4-8c5f7927bb96> in <module>
9 print(liste)
10
---> 11 list(map(change, liste ))
12
13

<ipython-input-4-8c5f7927bb96> in change(liste)
5 def change(liste):
6 temp = liste[0]
----> 7 liste[0] = liste[-1]
8 liste[-1] = temp
9 print(liste)

TypeError: 'str' object does not support item assignment


I tried making the list of lists manually
I wrote this-> liste = [[1,2,3,4],[2,3,4,5],[6,7,8,9]]
and it worked but I need to get this as an input.
Here's my Python code:



liste = input(" mat= ")

def change(liste):
temp = liste[0]
liste[0] = liste[-1]
liste[-1] = temp
print(liste)

list(map(change, liste ))









share|improve this question

























  • Without a sample input and desired output, it's hard to give an answer without knowing what to do.

    – Bazingaa
    Dec 31 '18 at 16:44













  • you can do: import ast; list(map(change, ast.literal_eval(liste )))

    – YOLO
    Dec 31 '18 at 16:54
















0















I can't get input a list of lists. I get this error :



TypeError                                 Traceback (most recent call last)
<ipython-input-4-8c5f7927bb96> in <module>
9 print(liste)
10
---> 11 list(map(change, liste ))
12
13

<ipython-input-4-8c5f7927bb96> in change(liste)
5 def change(liste):
6 temp = liste[0]
----> 7 liste[0] = liste[-1]
8 liste[-1] = temp
9 print(liste)

TypeError: 'str' object does not support item assignment


I tried making the list of lists manually
I wrote this-> liste = [[1,2,3,4],[2,3,4,5],[6,7,8,9]]
and it worked but I need to get this as an input.
Here's my Python code:



liste = input(" mat= ")

def change(liste):
temp = liste[0]
liste[0] = liste[-1]
liste[-1] = temp
print(liste)

list(map(change, liste ))









share|improve this question

























  • Without a sample input and desired output, it's hard to give an answer without knowing what to do.

    – Bazingaa
    Dec 31 '18 at 16:44













  • you can do: import ast; list(map(change, ast.literal_eval(liste )))

    – YOLO
    Dec 31 '18 at 16:54














0












0








0


1






I can't get input a list of lists. I get this error :



TypeError                                 Traceback (most recent call last)
<ipython-input-4-8c5f7927bb96> in <module>
9 print(liste)
10
---> 11 list(map(change, liste ))
12
13

<ipython-input-4-8c5f7927bb96> in change(liste)
5 def change(liste):
6 temp = liste[0]
----> 7 liste[0] = liste[-1]
8 liste[-1] = temp
9 print(liste)

TypeError: 'str' object does not support item assignment


I tried making the list of lists manually
I wrote this-> liste = [[1,2,3,4],[2,3,4,5],[6,7,8,9]]
and it worked but I need to get this as an input.
Here's my Python code:



liste = input(" mat= ")

def change(liste):
temp = liste[0]
liste[0] = liste[-1]
liste[-1] = temp
print(liste)

list(map(change, liste ))









share|improve this question
















I can't get input a list of lists. I get this error :



TypeError                                 Traceback (most recent call last)
<ipython-input-4-8c5f7927bb96> in <module>
9 print(liste)
10
---> 11 list(map(change, liste ))
12
13

<ipython-input-4-8c5f7927bb96> in change(liste)
5 def change(liste):
6 temp = liste[0]
----> 7 liste[0] = liste[-1]
8 liste[-1] = temp
9 print(liste)

TypeError: 'str' object does not support item assignment


I tried making the list of lists manually
I wrote this-> liste = [[1,2,3,4],[2,3,4,5],[6,7,8,9]]
and it worked but I need to get this as an input.
Here's my Python code:



liste = input(" mat= ")

def change(liste):
temp = liste[0]
liste[0] = liste[-1]
liste[-1] = temp
print(liste)

list(map(change, liste ))






python map-function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 16:46









Daniel Mesejo

18k21431




18k21431










asked Dec 31 '18 at 16:42









nnese nnese

6




6













  • Without a sample input and desired output, it's hard to give an answer without knowing what to do.

    – Bazingaa
    Dec 31 '18 at 16:44













  • you can do: import ast; list(map(change, ast.literal_eval(liste )))

    – YOLO
    Dec 31 '18 at 16:54



















  • Without a sample input and desired output, it's hard to give an answer without knowing what to do.

    – Bazingaa
    Dec 31 '18 at 16:44













  • you can do: import ast; list(map(change, ast.literal_eval(liste )))

    – YOLO
    Dec 31 '18 at 16:54

















Without a sample input and desired output, it's hard to give an answer without knowing what to do.

– Bazingaa
Dec 31 '18 at 16:44







Without a sample input and desired output, it's hard to give an answer without knowing what to do.

– Bazingaa
Dec 31 '18 at 16:44















you can do: import ast; list(map(change, ast.literal_eval(liste )))

– YOLO
Dec 31 '18 at 16:54





you can do: import ast; list(map(change, ast.literal_eval(liste )))

– YOLO
Dec 31 '18 at 16:54












1 Answer
1






active

oldest

votes


















1














Use `



import ast
liste = ast.literal_eval(input(" mat= "))`


As your error notifies you of, liste is a str. Every input is in fact a string. By using ast.literal_eval, it evaluates it and becomes a list of lists.






share|improve this answer


























  • Then someone inputs import os; os.remove(...) and you won't be happy. Better to use ast.literal_eval or json.loads.

    – a_guest
    Dec 31 '18 at 16:48













  • You are of course very right. If you write it as an answer, I'll remove mine. It all depends on who your users are, which I don't know in this case

    – Jondiedoop
    Dec 31 '18 at 16:51













  • You can include it in your answer, I don't mind.

    – a_guest
    Dec 31 '18 at 17:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989599%2fhow-can-i-input-a-list-of-lists-to-make-a-matrix-and-change-columns-by-using-map%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Use `



import ast
liste = ast.literal_eval(input(" mat= "))`


As your error notifies you of, liste is a str. Every input is in fact a string. By using ast.literal_eval, it evaluates it and becomes a list of lists.






share|improve this answer


























  • Then someone inputs import os; os.remove(...) and you won't be happy. Better to use ast.literal_eval or json.loads.

    – a_guest
    Dec 31 '18 at 16:48













  • You are of course very right. If you write it as an answer, I'll remove mine. It all depends on who your users are, which I don't know in this case

    – Jondiedoop
    Dec 31 '18 at 16:51













  • You can include it in your answer, I don't mind.

    – a_guest
    Dec 31 '18 at 17:00
















1














Use `



import ast
liste = ast.literal_eval(input(" mat= "))`


As your error notifies you of, liste is a str. Every input is in fact a string. By using ast.literal_eval, it evaluates it and becomes a list of lists.






share|improve this answer


























  • Then someone inputs import os; os.remove(...) and you won't be happy. Better to use ast.literal_eval or json.loads.

    – a_guest
    Dec 31 '18 at 16:48













  • You are of course very right. If you write it as an answer, I'll remove mine. It all depends on who your users are, which I don't know in this case

    – Jondiedoop
    Dec 31 '18 at 16:51













  • You can include it in your answer, I don't mind.

    – a_guest
    Dec 31 '18 at 17:00














1












1








1







Use `



import ast
liste = ast.literal_eval(input(" mat= "))`


As your error notifies you of, liste is a str. Every input is in fact a string. By using ast.literal_eval, it evaluates it and becomes a list of lists.






share|improve this answer















Use `



import ast
liste = ast.literal_eval(input(" mat= "))`


As your error notifies you of, liste is a str. Every input is in fact a string. By using ast.literal_eval, it evaluates it and becomes a list of lists.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 31 '18 at 17:01

























answered Dec 31 '18 at 16:46









JondiedoopJondiedoop

1,945214




1,945214













  • Then someone inputs import os; os.remove(...) and you won't be happy. Better to use ast.literal_eval or json.loads.

    – a_guest
    Dec 31 '18 at 16:48













  • You are of course very right. If you write it as an answer, I'll remove mine. It all depends on who your users are, which I don't know in this case

    – Jondiedoop
    Dec 31 '18 at 16:51













  • You can include it in your answer, I don't mind.

    – a_guest
    Dec 31 '18 at 17:00



















  • Then someone inputs import os; os.remove(...) and you won't be happy. Better to use ast.literal_eval or json.loads.

    – a_guest
    Dec 31 '18 at 16:48













  • You are of course very right. If you write it as an answer, I'll remove mine. It all depends on who your users are, which I don't know in this case

    – Jondiedoop
    Dec 31 '18 at 16:51













  • You can include it in your answer, I don't mind.

    – a_guest
    Dec 31 '18 at 17:00

















Then someone inputs import os; os.remove(...) and you won't be happy. Better to use ast.literal_eval or json.loads.

– a_guest
Dec 31 '18 at 16:48







Then someone inputs import os; os.remove(...) and you won't be happy. Better to use ast.literal_eval or json.loads.

– a_guest
Dec 31 '18 at 16:48















You are of course very right. If you write it as an answer, I'll remove mine. It all depends on who your users are, which I don't know in this case

– Jondiedoop
Dec 31 '18 at 16:51







You are of course very right. If you write it as an answer, I'll remove mine. It all depends on who your users are, which I don't know in this case

– Jondiedoop
Dec 31 '18 at 16:51















You can include it in your answer, I don't mind.

– a_guest
Dec 31 '18 at 17:00





You can include it in your answer, I don't mind.

– a_guest
Dec 31 '18 at 17:00




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989599%2fhow-can-i-input-a-list-of-lists-to-make-a-matrix-and-change-columns-by-using-map%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas