我有清单
pft_list = ['MM5 z no er ers pft\n', 'mm4 no z er efa pft\n',
'mm3 no z er xyz pft\n']
我已经用定界符分割了pft_list值并获取了第一个索引,我需要将获取的第一个索引分成一个列表。
for x in range(len(pfet_list)):
pfet_value = re.split(" ", pfet_list[x])
print(pfet_value[1])
value would be
z
no
no
从每个迭代字符串中获得预期结果,应将其转换为单个列表
pft_value1 = [z, no, no]
答案 0 :(得分:0)
您可以使用列表理解:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div id="wrapper-navbar" itemscope="" itemtype="http://schema.org/WebSite" class="fixed-top white-transp-gradient">
<a class="skip-link sr-only sr-only-focusable" href="#content">Salta al contenuto</a>
<nav class="navbar navbar-expand-md navbar-light bg-primary container">
<button class="navbar-toggler btn-primary" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- The WordPress Menu goes here -->
<div id="navbarNavDropdown" class="collapse navbar-collapse">
<ul id="main-menu" class="navbar-nav ml-auto">
<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement" id="menu-item-13" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home active menu-item-13 nav-item"><a title="Home" href="http://example.test/" class="nav-link">Home</a></li>
</ul>
</div>
</nav><!-- .site-navigation -->
</div>
输出:
pft_list = ['MM5 z no er ers pft\n', 'mm4 no z er efa pft\n',
'mm3 no z er xyz pft\n']
fList = [m.split(" ")[1] for m in pft_list ]
print(fList)