简体   繁体   English

如何将列表拆分为 2 位数字

[英]How to split a list into 2 digit numbers

I have this:我有这个:
a = ['a','b','c','d','e','f']

And I want to make it into this:我想把它变成这样:
a = ['ab','cd','ef']

What is the simplest way to about it?最简单的方法是什么?

def pair_up(a):
    return [a[i]+a[i+1] for i in range(0,len(a),2)]
print(pair_up(a))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将列表中的两位数字拆分为个位数? - How do to split the 2 digit numbers in a list into single digits? 如何按编号拆分列表? - How to split a list of list by numbers? 如何使用三位数字创建列表,其中第一位数字+第二位数字=第三位数字 - How to create list with 3- digit numbers which first digit + second digit = third digit 如何生成3位数字的列表? - how to generate a list of 3-digit numbers? 将数字附加到拆分列表 - Append digit to split list 用2位数字初始化列表 - initialize a list with 2 digit numbers 如何获取 4 位数字的所有可能组合的列表,其单个数字总和为 13,最后一位数字为 5 - how get list of all the possible combinations of 4 digit numbers whose individual digit sum is 13 and last digit is 5 in that number 如何将整数列表拆分为数字整数列表? - How do I split a list of integers into a list of digit integers? 如何将4位数字变量与4位数字列表进行比较,并确定它们是否具有完全相同的数字,而不管顺序如何? - How Can I Compare A 4 Digit Variable To A List Of 4 Digit Numbers And Determine If They Have The Exact Same Numbers, Regardless Of Order? 尝试输入一个分数并将其拆分为一个列表,但当数字超过 1 位时会导致问题 - Trying to input a fraction and split it into a list but it causes problem when the numbers are more than 1 digit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM