##### Turn coordinates in string into a tuple
 Turn coordinates in string into a tuple Kolterdyx Programmer named Tim Posts: 7 Threads: 6 Joined: Sep 2018 Reputation: Jun-09-2020, 09:20 PM (This post was last modified: Jun-09-2020, 09:34 PM by Kolterdyx.) I have a dict that stores chunk coordinates and their content in a game I'm making. It looks like this ```chunks = { '0,0' : , '0,1' : ... }```What I need is to get the keys, and turn them into coordinates, so I get a tuple like this: `'0,0' -> (0, 0)` Is there any way I can acomplish that? I worked it out, it actually was pretty simple: ```a = '1,2'.split(',') a = tuple(a) a = (int(a[0]), int(a[1])) print(a)`````Output:(1, 2)`` Reply micseydel Involuntary Spiderweb Collector Posts: 2,335 Threads: 60 Joined: Sep 2016 Reputation: Jun-09-2020, 09:49 PM Thanks for posting back your solution! You can do it in one line too `print(tuple(int(x) for x in '1,2'.split(',')))`or `print(tuple(map(int, '1,2'.split(','))))`Personally I prefer the first in Python, since comprehensions are more common than using things like map. Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more. Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :) Reply deanhystad So-and-so of the Yard Posts: 2,320 Threads: 11 Joined: Feb 2020 Reputation: Jun-10-2020, 02:12 AM Or you could save all you settings to a JSON file and not have to do any conversion at all. It might be worth investigating. Reply Posts: 7,605 Threads: 133 Joined: Sep 2016 Reputation: Jun-10-2020, 05:04 AM (This post was last modified: Jun-10-2020, 05:05 AM by buran.) this looks like XY problem: You have a dict and use str as key. why not use a tuple as key in dict in the first place? ```chunks = { (0, 0): , (0, 1): ... }```and because these are coordinates, you can go a step further and use namedtuple If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs Reply

 Possibly Related Threads… Thread Author Replies Views Last Post TypeError: __str__ returned non-string (type tuple) Anldra12 1 1,448 Apr-13-2021, 07:50 AM Last Post: Anldra12 code with no tuple gets : IndexError: tuple index out of range Aggam 4 858 Nov-04-2020, 11:26 AM Last Post: Aggam Import CSV data into array and turn into integers DoctorSmiles 5 1,045 Jul-16-2020, 10:47 AM Last Post: perfringo How do i turn my program into a .exe julio2000 1 771 Feb-14-2020, 08:18 PM Last Post: snippsat How do I turn a directory of HTML files into one CSV? glittergirl 2 829 Sep-21-2019, 05:33 PM Last Post: glittergirl Turn py into exe tester21 4 1,425 Jul-22-2019, 04:31 PM Last Post: nilamo How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? SukhmeetSingh 5 1,378 May-21-2019, 11:39 AM Last Post: avorane How to turn screen output into clickable hyperlinks windros 5 1,333 Jan-22-2019, 05:41 PM Last Post: windros Not sure how to turn this into a loop iamgonge 1 1,096 Dec-05-2018, 11:03 PM Last Post: anandoracledba Line of file from string to list to tuple vvarrior 2 3,575 Jun-01-2018, 08:56 PM Last Post: vvarrior

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020