Python列表索引拆分和操作(Python list index splitting and manipulation)
我的问题似乎很简单,但对于像我这样的Python新手来说,这对我来说太复杂了,所以情况如下:
我需要列出如下列表:
L = [(a, b, c), (d, e, d), (etc, etc, etc), (etc, etc, etc)]
并将每个索引设置为一个单独的列表,以便我可以专门从每个索引中提取元素。 问题是我实际上使用的列表包含数百个索引,比如上面的那些索引,我不能这样做:
L_new = list(L['insert specific index here'])
对于每一个人来说,这意味着会填充与第一个列表中的单个索引相对应的数百个列表的内存,并且从我的角度来看,将花费太多时间和内存。 所以我的问题是,如何分开这些索引,然后从它们中提取单个部分,而无需创建数百个单独的列表(至少不需要数百个单独的行来创建它们)。
My question seems simple, but for a novice to python like myself this is starting to get too complex for me to get, so here's the situation:
I need to take a list such as:
L = [(a, b, c), (d, e, d), (etc, etc, etc), (etc, etc, etc)]
and make each index an individual list so that I may pull elements from each index specifically. The problem is that the list I am actually working with contains hundreds of indices such as the ones above and I cannot make something like:
L_new = list(L['insert specific index here'])
for each one as that would mean filling up the memory with hundreds of lists corresponding to individual indices of the first list and would be far too time and memory consuming from my point of view. So my question is this, how can I separate those indices and then pull individual parts from them without needing to create hundreds of individual lists (at least to the point where I wont need hundreds of individual lines to create them).
原文:https://stackoverflow.com/questions/17238781
最满意答案
routes.MapRoute("Route 1", // Route name "product {prodId}/{action}/{code}", new { controller = "Product", //default controller=Product action = "Index", //default action= Index prodId = 12, //default prodId=12 code=UrlParameter.Optional // code is optional } ); www.xx.com/product 12/ >> Action: Overview, >> ProdId=12 passed as a param www.xx.com/product 12/Overview >> Action: Overview, >> ProdId=12 passed as a param www.xx.com/product 12/Results >> Action: Results, >> ProdId=12 passed as a param www.xx.com/product 12/Product >> Action: Product, >> ProdId=12 passed as a param >> Code="" passed as a param www.xx.com/product 12/Product/123 >> Action: Index, >> ProdId=12 passed as a param >> Code= 123 passed as a param
routes.MapRoute("Route 1", // Route name "product {prodId}/{action}/{code}", new { controller = "Product", //default controller=Product action = "Index", //default action= Index prodId = 12, //default prodId=12 code=UrlParameter.Optional // code is optional } ); www.xx.com/product 12/ >> Action: Overview, >> ProdId=12 passed as a param www.xx.com/product 12/Overview >> Action: Overview, >> ProdId=12 passed as a param www.xx.com/product 12/Results >> Action: Results, >> ProdId=12 passed as a param www.xx.com/product 12/Product >> Action: Product, >> ProdId=12 passed as a param >> Code="" passed as a param www.xx.com/product 12/Product/123 >> Action: Index, >> ProdId=12 passed as a param >> Code= 123 passed as a param
相关问答
更多-
主观普遍性(采取一撮盐): 首先,您对公司使用公司(单数),但是您使用联系人(复数)作为联系人。 从结构的角度来看,没有什么不对,但如果你的复数形式一致,你的用户会感谢你。 我会在两种情况下都使用复数形式,但这只是我的偏好......它看起来更像英语。 您也可以使用小写字母作为联系人,但大写则为公司。 看起来不专业。 接下来令人困惑的是您使用了两个{id}参数,一个用于公司,一个用于联系人。 我认为这些分别是公司和联系人的ID。 但是我很困惑,但作为人类,我能够像计算机一样推断上下文。 所以你最好在你的路线 ...
-
MVC3路由问题(MVC3 Routing question)[2023-05-30]
routes.MapRoute("Route 1", // Route name "product {prodId}/{action}/{code}", new { controller = "Product", //default controller=Product action = "Index", // ... -
在考虑周末之后,我决定使用“UseNamespaceFallback”。 我还实现了用户角色来管理每个用户可以访问的区域。 我认为这是一种更好的方法,因为我已经阅读了建议永远不要使用命名空间作为身份验证的方法。 After thinking about this though the weekend I decided to use "UseNamespaceFallback". I also implemented user roles to manage which areas each user ha ...
-
使用Request对象的Url属性 。 public ActionResult MyAction() { var url = Request.Url; /// ..... return View(); } 这将返回一个Uri对象与你需要的一切 。 您可能也对控制器的RouteData属性感兴趣,该属性提供了有关解析路线的更多详细信息。 Use the Url property of the Request object. public ActionResult MyAc ...
-
MVC3路由混乱(MVC3 routing confusion)[2023-12-18]
您只需要忽略第一个路径的路径字符串中的操作: routes.MapRoute( "picks", "picks/{teamID}/{week}", new { controller = "Picks", action = "Index", teamID = UrlParameter.Optional, week = UrlParameter.Optional }); 请记住在更通用的路线之上 ... -
其他人已经提出了很多建议,但是让我在这里提出一些其他的建议。 操作方法选择器 为了保持控制器操作的清洁,您可以编写一个操作方法选择器属性来创建两个简单的操作: [ActionName("Index")] public ActionResult IndexNonActivated(int id) { ... } [ActionName("Index")] [UserAccountActivated] public ActionResult IndexActivated(int id) { . ...
-
按照@BrettSmith发布的建议,我想出了以下解决方案: 我添加了第二个路径,其中包含锚点和约束,因此只有在指定锚点时才会选择此路径。 routes.MapRoute( "DocAnchor", // Route name "{controller}/{action}/{id}#{anchor}", // URL with parameters new { controller = "Home", action = "Index", id = UrlPar ...
-
MVC路由问题(MVC Routing question)[2022-07-21]
您应该将Year参数传递给BeginForm(),如: <% using (Html.BeginForm("Results", "Archive", new { year = DateTime.Now.Year })) { // form } %> You should pass the Year parameter to the BeginForm(), like: <% using (Html.BeginForm("Results", "Archiv ... -
映射路由MVC3(Map Routing MVC3)[2022-04-22]
自定义路由中有一个示例(根据您的情况进行了修改)。 Global.asax中: routes.MapRoute( "BrandDetails", "Brands/{brandID}", new { controller = "Brands", action = "Details" }, new { brandID = @"\d+" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", ... -
我最后使用以下答案在SignalR代码中修复此问题并提交拉取请求。 添加非mvc路由时,Html.ActionLink构造错误的链接 https://github.com/SignalR/SignalR/pull/19 I ended up fixing this in the SignalR code using the below answer and submitting a pull request. Html.ActionLink construct wrong link when a non-m ...