Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
列出2个相似的项目
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '15/5/7'
#没人比我更蛋疼了吧
a = [1,2,3,2]
from itertools import permutations
llist = len(a)
x = [((n+1)/(llist-1) if not (n+1)%(llist-1) else (n+1)/(llist-1)+1,n+1) for n,i in enumerate(permutations(a,2)) if i[0]==i[1]]
if x:
x = x[0]
print x[0],(x[0]-1)*(llist-1)+x[1]%(llist-1)+1 if x[1]%(llist-1) else llist
@ficapy

This comment has been minimized.

Copy link
Owner Author

ficapy commented May 7, 2015

为了不用for循环也是够拼的

for i,n in enumerate(a):
for x,y in enumerate(a[i+1:]):
if n ==y:
print i+1,i+x+2
break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.