Python-列出清单 [英] Python - make a list

查看:95
本文介绍了Python-列出清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何打开这样的内容:(不是文件)

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

这是我打印此内容时得到的:

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

对此:

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

推荐答案

使用str.splitlines分割字符串边界,并需要list.

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']

这篇关于Python-列出清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆