[英]how do i convert [“'c'”, “'d'”, “'a'”, “'b'”] into ['c','d','a','b']?? “” is a string type
how do I convert ["'c'", "'d'", "'a'", "'b'"]
into ['c','d','a','b']
"" is a string type如何将["'c'", "'d'", "'a'", "'b'"]
转换为['c','d','a','b']
"" 是字符串类型
You could use string slicing to remove the first and last character from a string:您可以使用字符串切片从字符串中删除第一个和最后一个字符:
l = ["'c'", "'d'", "'a'", "'b'"]
new = [x[1:-1] for x in l]
print(new)
Out:出去:
['c', 'd', 'a', 'b']
You can replace " ' "
(quotes) with ""
(blanks)您可以将" ' "
(引号)替换为""
(空格)
arr = ["'c'", "'d'", "'a'", "'b'"]
new_arr = [ele.replace("'","") for ele in arr ]
Out出去
['c', 'd', 'a', 'b']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.