本文介绍了如何加入整数数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我认为在Ruby中,如果你有一个整数数组(或列表) foo = [1,2,3] 你可以使用foo.join(",")将它们连接成一个字符串1,2,3 in Python ...是方法使用,,。join()?但是那时候一定要拿 a字符串列表......不是整数... 任何快速方法? 解决方案 加入前将它们转换为字符串: 在[145]中:foo = [1,2,3] 在[146]:'',''。join(map(str,foo)) Out [146]:''1,2, 3'' Ciao, Marc''BlackJack''Rintsch ''1,2, 3'' ''1,2,3'' 如果要将几个这样的结果写入文件,请考虑使用csv模块 。 HTH, John i think in Ruby, if you have an array (or list) of integersfoo = [1, 2, 3]you can use foo.join(",") to join them into a string "1,2,3"in Python... is the method to use ",".join() ? but then it must takea list of strings... not integers...any fast method? 解决方案Convert them to strings before joining:In [145]: foo = [1, 2, 3]In [146]: '',''.join(map(str, foo))Out[146]: ''1,2,3''Ciao,Marc ''BlackJack'' Rintsch''1,2,3''''1,2,3''If you are going to write several such results to a file, considerusing the csv module.HTH,John 这篇关于如何加入整数数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 09:40
查看更多