سلام

من خودم تازه کار هستم ولی فک کنم مشکل شما با تغییر خط زیر درست میشه

             total.append(args[j])

به

            total.append(j)

یعنی نیازی به args و [] نیست

2013/5/7 MersadKhan Mostaghimi <[email protected]>

> n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
> # Add your function here
>
> def flatten(args):
>
>     for i in args:
>         total=[]
>         for j in i:
>             total.append(args[j])
>     return total
> print flatten(n)
> من کل کد را به این شکل تغییر دادم ولی با این ارور رو به رو میشم؟
> (قصد صرفا یادگیری از پایه پایتونه!)
> Traceback (most recent call last):
>   File "python", line 11, in <module>
>   File "python", line 9, in flatten
> IndexError: list index out of range
>
> 2013/5/7, Ebrahim Radi <[email protected]>:
> > ببین! چه کاریه اصلا! واه. پایتونه دیگه :دی
> > راه یک: بسیار ساده:
> > sum(n,[])
> > راه دوم:
> > import itertools
> > list(itertools.chain.from_iterable(n))
> > شاد باشی :)
> >
> >
> > On Tue, 2013-05-07 at 22:11 +0430, nima rafiee wrote:
> >> baraye halghe for dovomie : faramoush shode ;)
> >>
> >>
> >>
> >>
> >> On Tue, May 7, 2013 at 10:00 PM, MersadKhan Mostaghimi
> >> <[email protected]> wrote:
> >>
> >>         n = [[1, 2, 3], [4, 5, 6, 7, 8, 9],[10, 11]]
> >>         # Add your function here
> >>         total = []
> >>         def flatten(*args):
> >>
> >>             for i in range(0,len(args)):
> >>                 for j in range(0,len(args[i]))
> >>                 total.append(args[i][j])
> >>             return total
> >>         print flatten(n)
> >>
> >>
> >  <
> >  <        من این کد را نوشتم ولی جواب نمیده ؟چرا؟
> >  <
> >>         --
> >>         MerSadKhaN
> >>
> >>
> >>         _______________________________________________
> >>         Py mailing list
> >>         [email protected]
> >>         http://isfahanlug.org/mailman/listinfo/py_isfahanlug.org
> >>
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> Py mailing list
> >> [email protected]
> >> http://isfahanlug.org/mailman/listinfo/py_isfahanlug.org
> >
>
>
> --
> MerSadKhaN
>
> _______________________________________________
> Py mailing list
> [email protected]
> http://isfahanlug.org/mailman/listinfo/py_isfahanlug.org
>



-- 
Best Regards

Babaei
_______________________________________________
Py mailing list
[email protected]
http://isfahanlug.org/mailman/listinfo/py_isfahanlug.org

Reply via email to