Python - make a list

2024/11/17 21:33:20

How can I turn something like this: (not a file)

Edit: It's what I get when I print this:

adjusted_coordinate_list = str(adjusted_X_coordinate) + ',' + str(Y_coordinate)1,1
1,2
1,3
1,4
1,5

into this:

['1,1','1,2','1,3','1,4',1,5']
Answer

Use str.splitlines to split over boundaries of string and needed a list.

s = """1,1
1,2
1,3
1,4
1,5"""
print s.splitlines()['1,1', '1,2', '1,3', '1,4', '1,5']
https://en.xdnf.cn/q/120155.html

Related Q&A

Error while running test case

I need to test my code below. I am using one test to see if it is working or not. but dont know what exactly I should pass as a parameter in the test code. Please see the test code at the end and pleas…

How to run something on each line of txt file?

I am trying to get this to run on each line of a .txt file.D1 =int(lines[0])*10 D2 =int(lines[1])*9 D3 =int(lines[2])*8 D4 =int(lines[3])*7 D5 =int(lines[4])*6 D6 =int(lines[5])*5 D7 =int(lines[6])*4 D…

Python np.nditer() - ValueError: Too many operands

I have a few methods which pass different amount of messy data to this function to combine headers with data and return a list of dictionaries:def zip_data(self, indicator_names, indicator_values):valu…

Python 3 - Find the Mode of a List

def mode(L):shows = []modeList = []L.sort()length = len(L)for num in L:count = L.count(num)shows.append(count)print List = , LmaxI = shows.index(max(shows))for i in shows:if i == maxI:if modeList == []…

Create list of sublists [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 9 years ago.Improve…

Python error - list index out of range?

Anyone help me see why I keep getting "list index out of range" as an error ?? def printInfo(average):average.sort() # sorts the list of tuples average.reverse() # reverses the list of tu…

Access strings inside a list

A Python list has [12:30,12:45] and I want to access the 12:30 for the first iteration, and on the second iteration I should get 12:45.my_list=[12:30,12:45] for each_value in my_list:print(each_value[0…

How do I install NumPy under Windows 8.1?

How do I install NumPy under Windows 8.1 ? Similar questions/answers on overflow hasnt helped.

Design In-Memory File System - Python - Trie - Leetcode Error

I am trying to solve the below leetcode problem Design a data structure that simulates an in-memory file system. Implement the FileSystem class: FileSystem() Initializes the object of the system. List …

OpenTurns Error when trying to use kernel build [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…